Struct async_local::Context
source · pub struct Context<T: Sync> { /* private fields */ }
Expand description
A wrapper type used for creating pointers to thread-locals that are valid within an async context
Implementations§
source§impl<T> Context<T>where
T: Sync,
impl<T> Context<T>where
T: Sync,
sourcepub fn new(inner: T) -> Context<T>
pub fn new(inner: T) -> Context<T>
Create a new thread-local context
Usage
Either wrap a type with Context and assign to a thread-local, or use as an unwrapped field in a struct that derives AsContext.
Example
use std::sync::atomic::AtomicUsize;
use async_local::Context;
thread_local! {
static COUNTER: Context<AtomicUsize> = Context::new(AtomicUsize::new(0));
}