vasi_sync::lazy_lock

Struct LazyLock

source
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>,

source

pub const fn const_new(initializer: Init) -> Self

source

pub fn new(initializer: Init) -> Self

source

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.

source

pub fn initd(&self) -> bool

Whether self is initialized yet.

Trait Implementations§

source§

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 UnsafeCells.

source§

type Target = T

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl<T, Init> Drop for LazyLock<T, Init>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T, Init> Send for LazyLock<T, Init>
where T: Send, Init: Send,

source§

impl<T, Init> Sync for LazyLock<T, Init>
where T: Sync, Init: Send,

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>
where Init: Unpin, T: Unpin,

§

impl<T, Init> UnwindSafe for LazyLock<T, Init>
where Init: 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.