Struct singleton::Singleton
[−]
[src]
pub struct Singleton<T: Send + Sync> { /* fields omitted */ }
A pointer type for holding shared global state in multi-thread environment.
Methods
impl<T: Send + Sync> Singleton<T>
[src]
pub fn new() -> Self
[src]
Create an uninitialized singleton.
pub fn get(&self) -> &T where
T: Default,
[src]
T: Default,
Access the singleton; initialize it with Default::default()
if it is uninitialized.
pub fn get_opt(&self) -> Option<&T>
[src]
Access the singleton; or return None
if it is not yet uninitialized.
pub fn get_or_insert_with<F>(&self, f: F) -> &T where
F: FnOnce() -> T,
[src]
F: FnOnce() -> T,
Access the singleton; initialize it with custom function if it is uninitialized.
pub unsafe fn finalize(&self)
[src]
Put the singleton into a finalized state, destruct the singleton value if it is initialized.
This is unsafe and only useful when the value holds other resources.