Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 8 additions & 10 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,13 @@ where
}

/// get pinned mutable referencial object that has self lifetime.
pub fn pin_mut<'s>(self: Pin<&'s mut Self>) -> Pin<&'s mut R::Type<'s>> {
let referential = self.project().referential;
unsafe { detach_lifetime_pin_mut::<R>(referential) }
pub fn pin_mut<'s>(self: Pin<&'s mut Self>) -> Pin<&'s mut R::Type<'a>> {
self.project().referential
}

/// get pinned referencial object that has self lifetime.
pub fn pin_ref<'s>(self: Pin<&'s Self>) -> Pin<&'s R::Type<'s>> {
let referential = self.project_ref().referential;
unsafe { detach_lifetime_pin_ref::<R>(referential) }
pub fn pin_ref<'s>(self: Pin<&'s Self>) -> Pin<&'s R::Type<'a>> {
self.project_ref().referential
}
}

Expand Down Expand Up @@ -137,13 +135,13 @@ where
}
}

pub fn get_ref<'s>(&'s self) -> &'s R::Type<'s> {
unsafe { detach_lifetime_get_ref::<R>(&self.referential) }
pub fn get_ref<'s>(&'s self) -> &'s R::Type<'a> {
&self.referential
}

/// get mutable reference from stable referential object.
pub fn get_mut<'s>(&'s mut self) -> &'s mut R::Type<'s> {
unsafe { detach_lifetime_get_mut::<R>(&mut self.referential) }
pub fn get_mut<'s>(&'s mut self) -> &'s mut R::Type<'a> {
&mut self.referential
}

pub fn into_inner(self) -> T {
Expand Down
47 changes: 0 additions & 47 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::refs::RefDef;

use core::mem;
use core::pin::Pin;

// SAFETY-NOTE: we are trasmutting same type with different lifetime, unless lifetime
// based generic speialization is on stable this is always safe.
Expand All @@ -17,49 +16,3 @@ where

return value;
}

#[inline]
pub unsafe fn detach_lifetime_get_ref<'this, R: ?Sized>(v: &'this R::Type<'_>) -> &'this R::Type<'this>
where
R: RefDef,
{
// I don't know why rustc indicates that different lifetime with same type has different size.
// we are just using trasmute_copy and forget instead of transmute.
let value = mem::transmute_copy(&v);
mem::forget(v);

return value;
}

#[inline]
pub unsafe fn detach_lifetime_get_mut<'this, R: ?Sized>(v: &'this mut R::Type<'_>) -> &'this mut R::Type<'this>
where
R: RefDef,
{
// I don't know why rustc indicates that different lifetime with same type has different size.
// we are just using trasmute_copy and forget instead of transmute.
let value = mem::transmute_copy(&v);
mem::forget(v);

return value;
}

#[inline]
pub unsafe fn detach_lifetime_pin_mut<'this, R: ?Sized>(
v: Pin<&mut R::Type<'_>>,
) -> Pin<&'this mut R::Type<'this>>
where
R: RefDef,
{
mem::transmute(v)
}

#[inline]
pub unsafe fn detach_lifetime_pin_ref<'this, R: ?Sized>(
v: Pin<&R::Type<'_>>,
) -> Pin<&'this R::Type<'this>>
where
R: RefDef,
{
mem::transmute(v)
}