[][src]Struct fumio_utils::current::Current

pub struct Current<T> { /* fields omitted */ }

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]

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]

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]

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

impl<T: Debug> Debug for Current<T>[src]

Auto Trait Implementations

impl<T> Unpin for Current<T> where
    T: Unpin

impl<T> Send for Current<T> where
    T: Send

impl<T> !Sync for Current<T>

impl<T> UnwindSafe for Current<T> where
    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]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]