pub struct GlobalMut<T> { /* private fields */ }
Expand description
A cell to store mutable reference.
§Safety
Because the implementation internally converts raw pointers to usize and shares them between threads, fetching references is essentially unsafe. Please verify its safety before using it.
Implementations§
Source§impl<T> GlobalMut<T>
impl<T> GlobalMut<T>
Sourcepub unsafe fn set(&self, item: &mut T)
pub unsafe fn set(&self, item: &mut T)
Set a reference so that other functions can obtain it through GlobalMut.
It is recommended to use with()
instead.
Be sure to call clear()
after it is used.
Sourcepub fn with<F, R>(&self, item: &mut T, f: F) -> Rwhere
F: FnOnce() -> R,
pub fn with<F, R>(&self, item: &mut T, f: F) -> Rwhere
F: FnOnce() -> R,
Set a reference and clear the reference after calling the given closure.
Sourcepub fn get(&self) -> &T
pub fn get(&self) -> &T
Get a immutable reference. Panics if set()
or with()
has not been called before.
Sourcepub fn try_get(&self) -> Option<&T>
pub fn try_get(&self) -> Option<&T>
Get a immutable reference. Returns None if set()
or with()
has not been called before.
Sourcepub fn get_mut(&self) -> &mut T
pub fn get_mut(&self) -> &mut T
Get a mutable reference. Panics if set()
or with()
has not been called before.
Sourcepub fn try_get_mut(&self) -> Option<&mut T>
pub fn try_get_mut(&self) -> Option<&mut T>
Get a mutable reference. Returns None if set()
or with()
has not been called before.