Skip to main content

LocalKey

Struct LocalKey 

Source
pub struct LocalKey<T: 'static> { /* private fields */ }
Expand description

A task-local key, declared with task_local!.

Implementations§

Source§

impl<T: 'static> LocalKey<T>

Source

pub fn scope<F: Future>( &'static self, value: T, future: F, ) -> TaskLocalFuture<T, F> ⓘ

A future that runs future with the key set to value in each of its polls, and drops future (when it is dropped early) with the value still set.

Source

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

Runs f with the key set to value, then unsets it.

Source

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

Runs f on the key’s value.

§Panics

Where no scope set the key; try_with answers an AccessError instead.

Source

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

Runs f on the key’s value, or answers an AccessError where no scope set it.

Source

pub fn get(&'static self) -> T
where T: Clone,

A clone of the key’s value.

§Panics

Where no scope set the key.

Trait Implementations§

Source§

impl<T: 'static> Debug for LocalKey<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for LocalKey<T>

§

impl<T> RefUnwindSafe for LocalKey<T>

§

impl<T> Send for LocalKey<T>

§

impl<T> Sync for LocalKey<T>

§

impl<T> Unpin for LocalKey<T>

§

impl<T> UnsafeUnpin for LocalKey<T>

§

impl<T> UnwindSafe for LocalKey<T>

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.

§

impl<T> MaybeSend for T
where T: Send + ?Sized,

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.