Struct ScopedKey

Source
pub struct ScopedKey<T> { /* private fields */ }
Expand description

Type representing a thread local storage key corresponding to a 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.

Implementations§

Source§

impl<T> ScopedKey<T>

Source

pub fn set<F, R>(&'static self, t: &T, f: F) -> R
where F: FnOnce() -> R,

Inserts a value into this scoped thread local storage slot for a duration of a closure.

While cb is running, the value t will be returned by get unless this function is called recursively inside of cb.

Upon return, this function will restore the previous value, if any was available.

Source

pub fn with<F, R>(&'static self, f: F) -> R
where F: FnOnce(&T) -> R,

Gets a value out of this scoped variable.

This function takes a closure which receives the value of this variable.

Source

pub fn try_with<F, R>(&'static self, f: F) -> R
where F: FnOnce(Option<&T>) -> R,

Gets a value out of this scoped variable.

Source

pub fn is_set(&'static self) -> bool

Test whether this TLS key has been set for the current thread.

Trait Implementations§

Source§

impl<T> Sync for ScopedKey<T>

Auto Trait Implementations§

§

impl<T> Freeze for ScopedKey<T>

§

impl<T> RefUnwindSafe for ScopedKey<T>
where T: RefUnwindSafe,

§

impl<T> Send for ScopedKey<T>
where T: Send,

§

impl<T> Unpin for ScopedKey<T>
where T: Unpin,

§

impl<T> UnwindSafe for ScopedKey<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.