Struct poplar_util::InitGuard

source ·
pub struct InitGuard<T> { /* private fields */ }
Expand description

A guard for when you want to store some data in a static, and explicitly initialize it at some point. This is different from spin::Once in that you do not need to provide an initialization method every time you access the object (it also uses MaybeUninit instead of Option). This will only release shared references to the data inside, so if you want to mutate it from mutable threads, you’ll need to use a type like Mutex or RwLock within this.

Implementations§

source§

impl<T> InitGuard<T>

source

pub const fn uninit() -> InitGuard<T>

source

pub fn initialize(&self, value: T)

Initialize this InitGuard, allowing it to be read from in the future.

§Panics

Panics if this InitGuard has already been initialized.

source

pub fn get(&self) -> &T

Get a reference to the data, if this guard has been initialized.

§Panics

Panics if this guard hasn’t been initialized yet. Use try_get if you want a fallible variant.

source

pub fn get_mut(&mut self) -> &mut T

Get a mutable reference to the data, if this guard has been initialized.

§Panics

Panics if this guard hasn’t been initialized yet. Use try_get_mut if you want a fallible variant.

source

pub fn try_get(&self) -> Option<&T>

Get a reference to the data, if this guard has been initialized. Returns None if it has not yet been initialized, or is currently being initialized.

source

pub fn try_get_mut(&mut self) -> Option<&mut T>

Get a mutable reference to the data, if this guard has been initialized. Returns None if it has not yet been initialized, or is currently being initialized.

Trait Implementations§

source§

impl<T: Send> Send for InitGuard<T>

source§

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

Auto Trait Implementations§

§

impl<T> !Freeze for InitGuard<T>

§

impl<T> !RefUnwindSafe for InitGuard<T>

§

impl<T> Unpin for InitGuard<T>
where T: Unpin,

§

impl<T> UnwindSafe for InitGuard<T>
where 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>,

§

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

§

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.