pub struct SharedGlobal<T> { /* private fields */ }Expand description
A global version of Shared. Use SharedGlobal::shared to get a Shared to access the contents.
Implementations§
Sourcepub const fn new(t: T) -> Self
pub const fn new(t: T) -> Self
Create a new SharedGlobal.
Sourcepub const fn new_lazy(f: fn() -> T) -> Self
pub const fn new_lazy(f: fn() -> T) -> Self
Create a new, lazy SharedGlobal implementation that will be initialized on the first access.
Sourcepub const fn new_unsync(t: T) -> Self
pub const fn new_unsync(t: T) -> Self
The SharedGlobal::new function requires a type that is both Send + Sync. If this is not possible, you may call
SharedGlobal::new_unsync to create a SharedGlobal implementation that uses a [Mutex].
This will fail to compile:
// Compiler error:
// error[E0277]: (type) cannot be shared between threads safely
// required by a bound in `keepcalm::Shared::<T>::new
SharedGlobal::new(Unsync {});This will work:
SharedGlobal::new_unsync(Unsync {});Sourcepub const fn new_lazy_unsync(f: fn() -> T) -> Self
pub const fn new_lazy_unsync(f: fn() -> T) -> Self
The SharedGlobal::new_lazy function requires a type that is both Send + Sync. If this is not possible, you may call
SharedGlobal::new_lazy to create a SharedGlobal implementation that uses a [Mutex].
Sourcepub const fn new_mutex(t: T) -> Self
pub const fn new_mutex(t: T) -> Self
Create a new SharedGlobal, backed by a Mutex and poisoning on panic.
Sourcepub const fn new_mutex_with_policy(t: T, policy: PoisonPolicy) -> Self
pub const fn new_mutex_with_policy(t: T, policy: PoisonPolicy) -> Self
Create a new SharedGlobal, backed by a Mutex and optionally poisoning on panic.
Sourcepub fn read(&'static self) -> SharedReadLock<'static, T>
pub fn read(&'static self) -> SharedReadLock<'static, T>
Lock the global SharedGlobal for reading directly.