Skip to main content

TaskLocal

Struct TaskLocal 

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

A key for task-local storage, created by the [task_local!] macro.

Each static TaskLocal<T> has a unique address used as the storage key.

Implementations§

Source§

impl<T: 'static> TaskLocal<T>

Source

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

Run future with value set for this key. Restores the previous value (if any) after each poll, so other tasks on the same thread don’t see stale data.

Source

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

Access the current value, panicking if no scope is active.

Source

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

Access the current value, returning Err if no scope is active.

Trait Implementations§

Source§

impl<T: 'static> Sync for TaskLocal<T>

Auto Trait Implementations§

§

impl<T> Freeze for TaskLocal<T>

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for TaskLocal<T>

§

impl<T> UnwindSafe for TaskLocal<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.