⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

OnceLock

Struct OnceLock 

Source
pub struct OnceLock<T> { /* private fields */ }
Expand description

A cell that can be written to only once (Rust 2024 compatible)

Similar to std::sync::OnceLock but works in no_std environments.

Implementations§

Source§

impl<T> OnceLock<T>

Source

pub const fn new() -> Self

Create a new empty OnceLock

Source

pub fn get(&self) -> Option<&'static T>

Get the value if initialized

Source

pub unsafe fn get_mut(&self) -> Option<&'static mut T>

Get mutable reference if initialized (unsafe)

§Safety

Caller must ensure exclusive access to the contained value for the duration of the returned reference’s lifetime. No other references (mutable or immutable) to the inner value may exist concurrently. Violating this invariant causes undefined behavior due to aliased mutable references.

Source

pub fn set(&self, value: T) -> Result<(), T>

Initialize the cell with a value

Returns Ok(()) if initialization succeeds, Err(value) if already initialized

Source

pub fn get_or_init<F>(&self, f: F) -> &'static T
where F: FnOnce() -> T,

Get or initialize the value

Trait Implementations§

Source§

impl<T> Default for OnceLock<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T> Drop for OnceLock<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Send> Send for OnceLock<T>

Source§

impl<T: Send + Sync> Sync for OnceLock<T>

Auto Trait Implementations§

§

impl<T> !Freeze for OnceLock<T>

§

impl<T> RefUnwindSafe for OnceLock<T>

§

impl<T> Unpin for OnceLock<T>

§

impl<T> UnwindSafe for OnceLock<T>
where T: RefUnwindSafe,

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.