Struct scoped_tls_hkt::ScopedKeyMut
source · [−]pub struct ScopedKeyMut<T: ?Sized + 'static> { /* private fields */ }
Expand description
Type representing a thread local storage key corresponding to a mutable reference
to the type parameter T
.
Keys are statically allocated and can contain a reference to an instance of
type T
scoped to a particular lifetime. Keys provides two methods, set
and with
, both of which currently use closures to control the scope of
their contents.
This differs from a ScopedKey
because it provides access through a mutable
reference. As a result, when the with(..)
method is used to access the value,
the key will appear unset whilst the closure is running. This is to prevent
the value being borrowed a second time.
Implementations
sourceimpl<T: ?Sized + 'static> ScopedKeyMut<T>
impl<T: ?Sized + 'static> ScopedKeyMut<T>
sourcepub fn set<F, R>(&'static self, t: &mut T, f: F) -> R where
F: FnOnce() -> R,
pub fn set<F, R>(&'static self, t: &mut T, f: F) -> R where
F: FnOnce() -> R,
Inserts a value into this scoped thread local storage slot for a duration of a closure.
sourcepub fn with<F, R>(&'static self, f: F) -> R where
F: FnOnce(&mut T) -> R,
pub fn with<F, R>(&'static self, f: F) -> R where
F: FnOnce(&mut T) -> R,
Gets a value out of this scoped variable.
This function takes a closure which receives the value of this variable. For the duration of the closure, the key will appear unset.
Panics
This function will panic if set
has not previously been called,
or if the call is nested inside another (multiple mutable borrows
of the same value are not allowed).
Trait Implementations
impl<T: ?Sized + 'static> Sync for ScopedKeyMut<T>
Auto Trait Implementations
impl<T: ?Sized> RefUnwindSafe for ScopedKeyMut<T>
impl<T: ?Sized> Send for ScopedKeyMut<T>
impl<T: ?Sized> Unpin for ScopedKeyMut<T>
impl<T: ?Sized> UnwindSafe for ScopedKeyMut<T>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more