pub struct LazyPinned<T>(pub Option<T>);
Expand description
Pinned data which can be lazily initialized.
§LazyPinned<T>
vs. Option<T>
LazyPinned<T>
act like Option<T>
.
In fact, LazyPinned<T>
is implemented by just wrapping Option<T>
.
However, they have different behaviors in pinning projection.
Pin<P<Option<T>>>
guarantees the Option<T>
is not moved,
where P<_>
is a pointer type which deref to _
.
Thus, when the data is None
, it cannot be set to Some(T)
unless
T: Unpin
.
Pin<P<LazyPinned<T>>>
only guarantees the inner T
is pinned.
Thus, Pin<&mut LazyPinned<T>>
optionally projects to Pin<&mut T>
instead of Pin<P<Option<T>>>
. When Pin<P<LazyPinned<T>>>
is None
,
it can be initialized with a value of T
.
Tuple Fields§
§0: Option<T>
Implementations§
Source§impl<T> LazyPinned<T>
impl<T> LazyPinned<T>
pub fn as_pin_ref(self: Pin<&Self>) -> Option<Pin<&T>>
pub fn as_pin_mut(self: Pin<&mut Self>) -> Option<Pin<&mut T>>
pub fn pin_project_or_insert(self: Pin<&mut Self>, v: T) -> Pin<&mut T>
pub fn pin_project_or_insert_with( self: Pin<&mut Self>, f: impl FnOnce() -> T, ) -> Pin<&mut T>
pub fn use_pin_or_insert( self: Pin<&mut Self>, use_pin: impl FnOnce(Pin<&mut T>), v: T, ) -> Pin<&mut T>
pub fn use_pin_or_insert_with( self: Pin<&mut Self>, use_pin: impl FnOnce(Pin<&mut T>), insert: impl FnOnce() -> T, ) -> Pin<&mut T>
pub fn use_pin_or_insert_with_data<Data>( self: Pin<&mut Self>, data: Data, use_pin: impl FnOnce(Data, Pin<&mut T>), insert: impl FnOnce(Data) -> T, ) -> Pin<&mut T>
Trait Implementations§
Source§impl<T: Clone> Clone for LazyPinned<T>
impl<T: Clone> Clone for LazyPinned<T>
Source§fn clone(&self) -> LazyPinned<T>
fn clone(&self) -> LazyPinned<T>
Returns a duplicate of the value. Read more
1.0.0 · Source§const fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl<T: Debug> Debug for LazyPinned<T>
impl<T: Debug> Debug for LazyPinned<T>
Source§impl<T> Default for LazyPinned<T>
impl<T> Default for LazyPinned<T>
Source§impl<T: Hash> Hash for LazyPinned<T>
impl<T: Hash> Hash for LazyPinned<T>
Source§impl<T: Ord> Ord for LazyPinned<T>
impl<T: Ord> Ord for LazyPinned<T>
Source§fn cmp(&self, other: &LazyPinned<T>) -> Ordering
fn cmp(&self, other: &LazyPinned<T>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: PartialEq> PartialEq for LazyPinned<T>
impl<T: PartialEq> PartialEq for LazyPinned<T>
Source§impl<T: PartialOrd> PartialOrd for LazyPinned<T>
impl<T: PartialOrd> PartialOrd for LazyPinned<T>
impl<T: Copy> Copy for LazyPinned<T>
impl<T: Eq> Eq for LazyPinned<T>
impl<T> StructuralPartialEq for LazyPinned<T>
Auto Trait Implementations§
impl<T> Freeze for LazyPinned<T>where
T: Freeze,
impl<T> RefUnwindSafe for LazyPinned<T>where
T: RefUnwindSafe,
impl<T> Send for LazyPinned<T>where
T: Send,
impl<T> Sync for LazyPinned<T>where
T: Sync,
impl<T> Unpin for LazyPinned<T>where
T: Unpin,
impl<T> UnwindSafe for LazyPinned<T>where
T: UnwindSafe,
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
Mutably borrows from an owned value. Read more