Struct ruspiro_singleton::Singleton[][src]

pub struct Singleton<T: 'static> { /* fields omitted */ }
Expand description

The Singleton wrapper stores any type

Implementations

Create a new Singleton instance to be used in a static variable. Only const fn constructors are allowed here.

Example

static FOO: Singleton<u32> = Singleton::new(20);

Create a new Singleton instance passing a closure that will be evaluated at first access to the contents of the singleton that will provide its value

Example

static FOO: Singleton<String> = Singleton::lazy(&|| String::from("foo"));

Take the stored singleton for whatever operation and prevent usage by other cores Safe access to the singleton mutable instance is guarantied inside the given closure.

Immutable access to a singleton for a specific operation. This access does not enforce any lock nor guarantees safe atomic access to the instance. However, it is usefull in read-only access scenarios like inside interrupt handlers.

Trait Implementations

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.