Skip to main content

ThreadLocalContext

Struct ThreadLocalContext 

Source
pub struct ThreadLocalContext;
Expand description

Thread-local context storage

This provides WASM-compatible thread-local context storage that automatically cleans up when contexts go out of scope.

Implementations§

Source§

impl ThreadLocalContext

Source

pub fn new() -> Self

Create a new thread-local context

Source

pub fn set<T: 'static>(&self, value: T)

Set a typed value in the context

Source

pub fn get<T: 'static + Clone>(&self) -> Option<T>

Get a typed value from the context

Source

pub fn remove<T: 'static>(&self) -> Option<T>

Remove a typed value from the context

Source

pub fn clear(&self)

Clear all context values

Source

pub fn scoped<T: 'static + Clone>( &self, value: T, ) -> Guard<T, impl FnOnce(T) + use<T>>

Create a scoped context guard for a typed value

Trait Implementations§

Source§

impl Default for ThreadLocalContext

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> IntoScoped for T

Source§

type Resource = T

Source§

fn into_scoped(self) -> <T as IntoScoped>::Resource

Convert into a scoped resource
Source§

fn scoped<F, R>(self, f: F) -> R
where Self: Sized, F: FnOnce(&Self::Resource) -> R,

Execute a scoped operation with this resource
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.