[−][src]Struct global::Global
A mutable 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.
Methods
impl<T> Global<T>
[src]
impl<T: Default + 'static> Global<T>
[src]
pub fn with<F, R>(&self, f: F) -> R where
F: FnOnce(&T) -> R,
[src]
F: FnOnce(&T) -> R,
Run a closure on an immutable reference to the inner value.
This will return the closure's return type. Internally, lock
is
called and unwrapped.
Panics
This will panic if the value is already borrowed mutably in the same thread.
pub fn with_mut<F, R>(&self, f: F) -> R where
F: FnOnce(&mut T) -> R,
[src]
F: FnOnce(&mut T) -> R,
Run a closure on a mutable reference to the inner value.
This will return the closure's return type. Internally, lock_mut
is
called and unwrapped.
Panics
This will panic if the value is already borrowed either mutably or immutably in the same thread.
pub fn lock(&self) -> Result<GlobalGuard<T>, BorrowFail>
[src]
Obtain a lock providing an immutable reference to the inner value.
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.
pub fn lock_mut(&self) -> Result<GlobalGuardMut<T>, BorrowFail>
[src]
Obtain a lock providing a mutable reference to the inner value.
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.
pub fn force_init(&self)
[src]
Force the inner value to be initialized.
This will only initialize the value if it has not already been initialized.
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,