Struct agb::sync::InitOnce

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

A helper type that ensures a particular value is only initialized once.

Implementations§

source§

impl<T> InitOnce<T>

source

pub const fn new() -> Self

Creates a new uninitialized object.

source

pub fn get(&self, initializer: impl FnOnce() -> T) -> &T

Gets the contents of this state, or initializes it if it has not already been initialized.

The initializer function is guaranteed to only be called once.

This function disables IRQs while it is initializing the inner value. While this can cause audio skipping and other similar issues, it is not normally a problem as interrupts will only be disabled once per InitOnce during the life cycle of the program.

source

pub fn try_get<E>( &self, initializer: impl FnOnce() -> Result<T, E> ) -> Result<&T, E>

Gets the contents of this state, or initializes it if it has not already been initialized.

The initializer function is guaranteed to only be called once if it returns Ok. If it returns Err, it will be called again in the future until an attempt at initialization succeeds.

This function disables IRQs while it is initializing the inner value. While this can cause audio skipping and other similar issues, it is not normally a problem as interrupts will only be disabled once per InitOnce during the life cycle of the program.

Trait Implementations§

source§

impl<T> Drop for InitOnce<T>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl<T: Send> Send for InitOnce<T>

source§

impl<T: Sync> Sync for InitOnce<T>

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for InitOnce<T>

§

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

§

impl<T> UnwindSafe for InitOnce<T>where T: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere 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 Twhere 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.