pub struct Singleton<T: Send + Sync> { /* private fields */ }
Expand description
A pointer type for holding shared global state in multi-thread environment.
Implementations§
Source§impl<T: Send + Sync> Singleton<T>
impl<T: Send + Sync> Singleton<T>
Sourcepub fn get(&self) -> &Twhere
T: Default,
pub fn get(&self) -> &Twhere
T: Default,
Access the singleton; initialize it with Default::default()
if it is uninitialized.
Sourcepub fn get_opt(&self) -> Option<&T>
pub fn get_opt(&self) -> Option<&T>
Access the singleton; or return None
if it is not yet uninitialized.
Sourcepub fn get_or_insert_with<F>(&self, f: F) -> &Twhere
F: FnOnce() -> T,
pub fn get_or_insert_with<F>(&self, f: F) -> &Twhere
F: FnOnce() -> T,
Access the singleton; initialize it with custom function if it is uninitialized.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Singleton<T>
impl<T> RefUnwindSafe for Singleton<T>
impl<T> Send for Singleton<T>
impl<T> Sync for Singleton<T>
impl<T> Unpin for Singleton<T>
impl<T> UnwindSafe for Singleton<T>where
T: RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more