Expand description
Task-local storage for async contexts.
Provides TaskLocal<T> — a key for per-task storage, analogous to
thread_local! but scoped to an async task’s execution. Values are set
via TaskLocal::scope and read via TaskLocal::with /
TaskLocal::try_with.
§Example
moduvex_runtime::task_local! {
static REQUEST_ID: u64;
}
moduvex_runtime::block_on(async {
REQUEST_ID.scope(42, async {
REQUEST_ID.with(|id| assert_eq!(*id, 42));
}).await;
});Structs§
- Access
Error - Returned by
TaskLocal::try_withwhen no scope is active. - Scope
- A future that sets a task-local value around each poll of an inner future.
- Task
Local - A key for task-local storage, created by the [
task_local!] macro.