pub struct TempInstPin<'a, T: TempReprMut + 'a>(/* private fields */);
Expand description
A wrapper around an instance of T
which implements TempReprMut
, i.e. is a temporary
representation of a type T::Mutable<'a>
.
TempInstPin
itself has a lifetime parameter 'a
and borrows the object passed to
TempInstPin::new
for that lifetime; therefore it is logically equivalent to
T::Mutable<'a>
. However, it can hand out references to the lifetime-less type T
via
TempInstPin::deref_pin
. The references have type Pin<&mut T>
; use the slightly less
efficient TempInstMut
wrapper if &mut T
is required instead.
Implementations§
Source§impl<'a, T: TempReprMut> TempInstPin<'a, T>
impl<'a, T: TempReprMut> TempInstPin<'a, T>
Sourcepub fn new(obj: T::Mutable<'a>) -> Self
pub fn new(obj: T::Mutable<'a>) -> Self
Creates a TempInstPin
from an instance of T::Mutable
.
A pinned mutable reference to T
can be obtained from the result via Self::deref_pin
.
As deref_pin
expects self
to be pinned, use the core::pin::pin!
macro to pin the
result of Self::new
on the stack.
Note that only the TempInstPin
reference will be pinned; this is completely independent
of whether T::Mutable
is a pinned reference. E.g. T
can be TempRefMut
or
TempRefPin
, and then T::get_mut_pinned
will return a mutable or pinned mutable
reference accordingly.
§Remarks
For many types, including TempRef
, T::Mutable
is actually the same as T::Shared
.
This can be useful when combining mutable and shared references in a tuple. E.g.
T = (TempRefMut<U>, TempRef<V>)
represents (&mut U, &V)
, and this is preserved by
TempInstPin::new
, whereas TempInst::new
treats it as (&U, &V)
.
Sourcepub fn deref_pin(self: Pin<&mut Self>) -> Pin<&mut T>
pub fn deref_pin(self: Pin<&mut Self>) -> Pin<&mut T>
Dereferences a pinned mutable TempInstMut
reference to obtain a pinned mutable reference
to T
. From that reference, the original object can be obtained via
TempReprMut::get_mut_pinned
.
Sourcepub fn call_with<R>(obj: T::Mutable<'a>, f: impl FnOnce(Pin<&mut T>) -> R) -> R
pub fn call_with<R>(obj: T::Mutable<'a>, f: impl FnOnce(Pin<&mut T>) -> R) -> R
Calls f
with a pinned mutable reference to T
which is constructed from obj
, and
returns the value returned by f
.
This method exists for consistency (with respect to TempInstMut::call_with
), but is
actually just a trivial application of Self::new
and Self::deref_pin
.
Trait Implementations§
Source§impl<'a, T: Clone + TempReprMut + 'a> Clone for TempInstPin<'a, T>
impl<'a, T: Clone + TempReprMut + 'a> Clone for TempInstPin<'a, T>
Source§fn clone(&self) -> TempInstPin<'a, T>
fn clone(&self) -> TempInstPin<'a, T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl<T: TempReprMut + Debug> Debug for TempInstPin<'_, T>
impl<T: TempReprMut + Debug> Debug for TempInstPin<'_, T>
Source§impl<'a, T: TempReprMut<Mutable<'a>: Default>> Default for TempInstPin<'a, T>
impl<'a, T: TempReprMut<Mutable<'a>: Default>> Default for TempInstPin<'a, T>
Source§impl<T: TempReprMut> Deref for TempInstPin<'_, T>
impl<T: TempReprMut> Deref for TempInstPin<'_, T>
Source§impl<T: TempReprMut + Display> Display for TempInstPin<'_, T>
impl<T: TempReprMut + Display> Display for TempInstPin<'_, T>
Source§impl<'a, T: Hash + TempReprMut + 'a> Hash for TempInstPin<'a, T>
impl<'a, T: Hash + TempReprMut + 'a> Hash for TempInstPin<'a, T>
Source§impl<'a, T: Ord + TempReprMut + 'a> Ord for TempInstPin<'a, T>
impl<'a, T: Ord + TempReprMut + 'a> Ord for TempInstPin<'a, T>
Source§fn cmp(&self, other: &TempInstPin<'a, T>) -> Ordering
fn cmp(&self, other: &TempInstPin<'a, T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Source§impl<'a, T: PartialEq + TempReprMut + 'a> PartialEq for TempInstPin<'a, T>
impl<'a, T: PartialEq + TempReprMut + 'a> PartialEq for TempInstPin<'a, T>
Source§impl<'a, T: PartialOrd + TempReprMut + 'a> PartialOrd for TempInstPin<'a, T>where
T::Mutable<'a>: PartialOrd,
impl<'a, T: PartialOrd + TempReprMut + 'a> PartialOrd for TempInstPin<'a, T>where
T::Mutable<'a>: PartialOrd,
impl<'a, T: Copy + TempReprMut + 'a> Copy for TempInstPin<'a, T>
impl<'a, T: Eq + TempReprMut + 'a> Eq for TempInstPin<'a, T>
impl<'a, T: TempReprMut + 'a> StructuralPartialEq for TempInstPin<'a, T>
Auto Trait Implementations§
impl<'a, T> Freeze for TempInstPin<'a, T>where
T: Freeze,
impl<'a, T> RefUnwindSafe for TempInstPin<'a, T>
impl<'a, T> Send for TempInstPin<'a, T>
impl<'a, T> Sync for TempInstPin<'a, T>
impl<'a, T> Unpin for TempInstPin<'a, T>
impl<'a, T> UnwindSafe for TempInstPin<'a, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more