[−][src]Struct fumio_utils::current::Current
Holds a value when entered or nothing when not.
Methods
impl<T> Current<T>
[src]
pub const fn new() -> Self
[src]
Construct a new (empty) instance.
pub fn enter<F, R>(
this: &'static LocalKey<Self>,
enter: &mut Enter,
value: T,
f: F
) -> R where
F: FnOnce(&mut Enter) -> R,
[src]
this: &'static LocalKey<Self>,
enter: &mut Enter,
value: T,
f: F
) -> R where
F: FnOnce(&mut Enter) -> R,
Set instance to value
while running the callback.
On exit the instance is cleared.
Panics
Panics if the instance already was entered.
pub fn with<F, R>(this: &'static LocalKey<Self>, f: F) -> R where
F: FnOnce(Option<&T>) -> R,
[src]
F: FnOnce(Option<&T>) -> 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.
pub fn with_mut<F, R>(this: &'static LocalKey<Self>, f: F) -> R where
F: FnOnce(Option<&mut T>) -> R,
[src]
F: FnOnce(Option<&mut T>) -> 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> Unpin for Current<T> where
T: Unpin,
T: Unpin,
impl<T> Send for Current<T> where
T: Send,
T: Send,
impl<T> !Sync for Current<T>
impl<T> UnwindSafe for Current<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> !RefUnwindSafe for Current<T>
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,