pub struct Global<T> { /* private fields */ }
Expand description
A global value.
All types wrapped in Global
must implement Default
. This gives the
initial value of the global variable.
Handles to this value can be obtained with the Global::lock
or
Global::lock_mut
methods.
Implementations§
source§impl<T: Default + Send + 'static> Global<T>
impl<T: Default + Send + 'static> Global<T>
sourcepub const INIT: Global<T> = _
pub const INIT: Global<T> = _
The initial global value.
The docs here will show you the internals of Global::INIT
, however
this is not intended to be visible. Once const fn
is stabilized, this
will become a const fn
.
sourcepub fn new() -> Self
pub fn new() -> Self
A non-constant version of Global::INIT
.
Prefer the constant value where possible.
sourcepub fn lock(&self) -> Result<GlobalGuard<T>, BorrowFail>
pub fn lock(&self) -> Result<GlobalGuard<T>, BorrowFail>
Obtain a lock providing an immutable reference to the inner value0.
This method will block the current thread until any other threads holding a lock are destroyed. If the current thread already has mutable access, this method will return an error.
sourcepub fn lock_mut(&self) -> Result<GlobalGuardMut<T>, BorrowFail>
pub fn lock_mut(&self) -> Result<GlobalGuardMut<T>, BorrowFail>
Obtain a lock providing a mutable reference to the inner value0.
This method will block the current thread until any other threads holding a lock are destroyed. If the current thread already has access, whether mutable or immutable, this method will return an error.