Trait AsyncLocal

Source
pub trait AsyncLocal<T>
where T: AsContext,
{ // Required methods fn with_blocking<F, R>(&'static self, f: F) -> JoinHandle<R> where F: for<'id> FnOnce(LocalRef<'id, T::Target>) -> R + Send + 'static, R: Send + 'static; fn with_async<F, R>(&'static self, f: F) -> impl Future<Output = R> where F: for<'a> AsyncFnMut(LocalRef<'a, T::Target>) -> R; fn local_ref<'id>( &'static self, guard: Guard<'id>, ) -> LocalRef<'id, T::Target>; }
Expand description

LocalKey extension for creating thread-safe pointers to thread-local Context

Required Methods§

Source

fn with_blocking<F, R>(&'static self, f: F) -> JoinHandle<R>
where F: for<'id> FnOnce(LocalRef<'id, T::Target>) -> R + Send + 'static, R: Send + 'static,

Available on crate feature rt only.

A wrapper around tokio::task::spawn_blocking that safely constrains the lifetime of LocalRef

Source

fn with_async<F, R>(&'static self, f: F) -> impl Future<Output = R>
where F: for<'a> AsyncFnMut(LocalRef<'a, T::Target>) -> R,

Acquire a reference to the value in this TLS key.

Source

fn local_ref<'id>(&'static self, guard: Guard<'id>) -> LocalRef<'id, T::Target>

Create a pointer to a thread local Context using a trusted lifetime carrier.

§Usage

Use generativity::make_guard to generate a unique invariant lifetime brand

§Panic

LocalRef must be created within the async context of the runtime.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T> AsyncLocal<T> for LocalKey<T>
where T: AsContext,

Source§

fn with_blocking<F, R>(&'static self, f: F) -> JoinHandle<R>
where F: for<'id> FnOnce(LocalRef<'id, T::Target>) -> R + Send + 'static, R: Send + 'static,

Available on crate feature rt only.
Source§

async fn with_async<F, R>(&'static self, f: F) -> R
where F: for<'a> AsyncFnMut(LocalRef<'a, T::Target>) -> R,

Source§

fn local_ref<'id>(&'static self, guard: Guard<'id>) -> LocalRef<'id, T::Target>

Implementors§