[−][src]Struct ruspiro_singleton::Singleton
The Singleton wrapper stores any type
Methods
impl<T: 'static> Singleton<T>
[src]
pub const fn new(data: T) -> Singleton<T>
[src]
Create a new singleton instance to be used in a static variable. Only const fn
constructors are allowed here.
If this is not sufficient the Singleton
may be further wrapped by a lazy_static!
available as
external crate from crates.io
pub fn take_for<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.
Example
FOO.take_for(|foo| { // do something mutable with [foo] });
pub fn use_for<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.
Example
FOO.use_for(|foo| { // do something immutable with [foo] });
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = !
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
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>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,