[][src]Struct ruspiro_singleton::Singleton

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

The Singleton wrapper stores any type

Implementations

impl<T: 'static> Singleton<T>[src]

pub const fn new(value: T) -> Self[src]

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);

pub const fn lazy<F>(init: &'static F) -> Self where
    F: Fn() -> T, 
[src]

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"));

pub fn with_mut<F, R>(&self, f: F) -> R where
    F: FnOnce(&mut T) -> R, 
[src]

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.

pub fn with_ref<F, R>(&self, f: F) -> R where
    F: FnOnce(&T) -> R, 
[src]

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

impl<T> Send for Singleton<T>[src]

impl<T> Sync for Singleton<T>[src]

Auto Trait Implementations

impl<T> Unpin for Singleton<T> where
    T: Unpin

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.