[−][src]Struct ruspiro_singleton::Singleton
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]
F: Fn() -> T,
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]
F: FnOnce(&mut T) -> R,
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]
F: FnOnce(&T) -> R,
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
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,