Struct singleton::PreemptiveSingleton
[−]
[src]
pub struct PreemptiveSingleton<T: Send> { /* fields omitted */ }
A pointer type for holding non-shared global state in multi-thread environment. Only the thread that sucessfully put data in it can access the data.
Methods
impl<T: Send> PreemptiveSingleton<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.
Panic if it is taken previously by another thread.
pub fn get_opt(&self) -> Option<&T>
[src]
Access the singleton; or return None
if it is not yet uninitialized or taken previously
by another thread.
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. Panic if it is taken previously by another thread.
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.