pub(super) struct Lazy<T, F> {
data: AtomicPtr<T>,
create: F,
owned: PhantomData<Box<T>>,
}Expand description
A non-std lazy initialized value.
This might run the initialization function more than once, but will never block.
I wish I could get these semantics into the non-alloc non-std Lazy type below, but I’m not sure how to do it. If you can do an alloc, then the implementation becomes very simple if you don’t care about redundant work precisely because a pointer can be atomically swapped.
Perhaps making this approach work in the non-alloc non-std case requires asking the caller for a pointer? It would make the API less convenient I think.
Fields§
§data: AtomicPtr<T>§create: F§owned: PhantomData<Box<T>>Implementations§
Trait Implementations§
impl<T: Send + Sync, F: Send + Sync> Sync for Lazy<T, F>
Auto Trait Implementations§
impl<T, F> !Freeze for Lazy<T, F>
impl<T, F> RefUnwindSafe for Lazy<T, F>where
F: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, F> Send for Lazy<T, F>
impl<T, F> Unpin for Lazy<T, F>where
F: Unpin,
impl<T, F> UnsafeUnpin for Lazy<T, F>where
F: UnsafeUnpin,
impl<T, F> UnwindSafe for Lazy<T, F>
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