pub struct LazyLock<T, Init = fn() -> T> { /* private fields */ }
Expand description
Analogous to std::sync::LazyLock
, but works on stable Rust, is no_std,
only makes direct syscalls, etc.
Implementations§
source§impl<T, Init> LazyLock<T, Init>where
Init: Producer<T>,
impl<T, Init> LazyLock<T, Init>where
Init: Producer<T>,
pub const fn const_new(initializer: Init) -> Self
pub fn new(initializer: Init) -> Self
sourcepub fn force(&self) -> Ref<'_, T>
pub fn force(&self) -> Ref<'_, T>
Force initialization and return a reference object.
std’s LazyLock returns an actual reference here and implements Deref. We can’t because of our usage of loom’s UnsafeCell, which doesn’t support getting a raw reference that’s not borrowed from an intermediate temp object.
Trait Implementations§
source§impl<T, Init> Deref for LazyLock<T, Init>where
Init: Producer<T>,
impl<T, Init> Deref for LazyLock<T, Init>where
Init: Producer<T>,
We only implement Deref outside of Loom, since Loom requires an intermediate
object to catch invalid accesses to our internal UnsafeCell
s.
impl<T, Init> Send for LazyLock<T, Init>
impl<T, Init> Sync for LazyLock<T, Init>
Auto Trait Implementations§
impl<T, Init = fn() -> T> !Freeze for LazyLock<T, Init>
impl<T, Init = fn() -> T> !RefUnwindSafe for LazyLock<T, Init>
impl<T, Init> Unpin for LazyLock<T, Init>
impl<T, Init> UnwindSafe for LazyLock<T, Init>where
Init: UnwindSafe,
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