Struct SelfReference

Source
pub struct SelfReference<'a, T, R>
where R: RefDef + 'a,
{ /* private fields */ }
Expand description

A Self-Referential Helper.

Implementations§

Source§

impl<'a, T, R> SelfReference<'a, T, R>
where R: RefDef + 'a,

Source

pub fn new<F>(object: T, init: F) -> Self
where R: 'static, F: FnOnce() -> R::Type<'static>,

You will “never” able to hold object before its pinned. try initializing as empty static object. (using Option, NonNull or Empty enum field)

Source

pub fn new_stable<F>(object: T, init: F) -> Self
where T: StableDeref + DerefMut, F: FnOnce(&mut T::Target) -> R::Type<'_>,

Source

pub fn reset<'s, F>(self: Pin<&'s mut Self>, f: F)
where F: FnOnce(Pin<&'s mut T>) -> R::Type<'s>,

reset referenceial object using object. object is now pinned so initializing referential type is safe. This is also useful when you consumed your own reference. (like in AsyncIterator)

Source

pub fn pin_mut<'s>(self: Pin<&'s mut Self>) -> Pin<&'s mut R::Type<'s>>

get pinned mutable referencial object that has self lifetime.

Source

pub fn pin_ref<'s>(self: Pin<&'s Self>) -> Pin<&'s R::Type<'s>>

get pinned referencial object that has self lifetime.

Source§

impl<'a, T, R> SelfReference<'a, T, R>
where R: RefDef, T: Unpin,

Source

pub fn reset_unpin<'s, F>(self: Pin<&'s mut Self>, f: F)
where F: FnOnce(&'s mut T) -> R::Type<'s>,

reset referenceial object using unpinned object. object is now pinned so initializing referential type is safe. This is also useful when you consumed your own reference. (like in AsyncIterator)

Source§

impl<'a, T, R> SelfReference<'a, T, R>
where R: RefDef, T: StableDeref,

Source

pub fn map<'s, F, N>(self, f: F) -> SelfReference<'a, T, N>
where for<'this> <R as RefDef>::Type<'this>: Unpin, T: 's, R: 's, N: RefDef + 's, F: FnOnce(R::Type<'s>) -> N::Type<'s>,

Source

pub fn get_ref<'s>(&'s self) -> &'s R::Type<'s>

Source

pub fn get_mut<'s>(&'s mut self) -> &'s mut R::Type<'s>

Source

pub fn into_inner(self) -> T

Trait Implementations§

Source§

impl<'pin, 'a, T, R> Unpin for SelfReference<'a, T, R>
where R: RefDef + 'a, PinnedFieldsOf<Wrapper<'pin, Self>>: UnsafeUnpin,

Source§

impl<'a, T, R> UnsafeUnpin for SelfReference<'a, T, R>
where R: RefDef, T: StableDeref,

Auto Trait Implementations§

§

impl<'a, T, R> Freeze for SelfReference<'a, T, R>
where <R as RefDef>::Type<'a>: Freeze, T: Freeze,

§

impl<'a, T, R> RefUnwindSafe for SelfReference<'a, T, R>
where <R as RefDef>::Type<'a>: RefUnwindSafe, T: RefUnwindSafe,

§

impl<'a, T, R> Send for SelfReference<'a, T, R>
where <R as RefDef>::Type<'a>: Send, T: Send,

§

impl<'a, T, R> Sync for SelfReference<'a, T, R>
where <R as RefDef>::Type<'a>: Sync, T: Sync,

§

impl<'a, T, R> UnwindSafe for SelfReference<'a, T, R>
where <R as RefDef>::Type<'a>: UnwindSafe, T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.