pub struct Current<T> { /* private fields */ }Expand description
Holds a value when entered or nothing when not.
Implementations§
Source§impl<T> Current<T>
impl<T> Current<T>
Sourcepub fn enter<F, R>(
this: &'static LocalKey<Self>,
enter: &mut Enter,
value: T,
f: F,
) -> R
pub fn enter<F, R>( this: &'static LocalKey<Self>, enter: &mut Enter, value: T, f: F, ) -> R
Set instance to value while running the callback.
On exit the instance is cleared.
§Panics
Panics if the instance already was entered.
Sourcepub fn with<F, R>(this: &'static LocalKey<Self>, f: F) -> R
pub fn with<F, R>(this: &'static LocalKey<Self>, f: F) -> R
Run callback with a reference to the current value (if there is one)
The callback will be called while holding a shareable lock to the inner value.
§Panics
Panics if the inner value is currently locked exclusively by a with_mut call.
Sourcepub fn with_mut<F, R>(this: &'static LocalKey<Self>, f: F) -> R
pub fn with_mut<F, R>(this: &'static LocalKey<Self>, f: F) -> R
Run callback with a reference to the current value (if there is one)
The callback will be called while holding an exclusive lock to the inner value.
§Panics
Panics if the inner value is currently locked by a with or a with_mut call.
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Current<T>
impl<T> !RefUnwindSafe for Current<T>
impl<T> Send for Current<T>where
T: Send,
impl<T> !Sync for Current<T>
impl<T> Unpin for Current<T>where
T: Unpin,
impl<T> UnwindSafe for Current<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more