Provides a type-safe task-local container for arbitrary data keyed by types.
Add task-local-extensions
to your dependencies
```toml [dependencies]
task-local-extensions = "0.1.0" ```
Extensions
is a container that can store up to one value of each type, so you can insert and retrive values by
their type:
```rust use tasklocalextensions::Extensions;
let a: i64 = 3;
let mut ext = Extensions::new();
extensions.insert(a);
assert_eq!(ext.get::
The crate also provides with_extensions
so you set an Extensions
instance while running a given task:
```rust use tasklocalextensions::{getlocalitem, setlocalitem, with_extensions, Extensions};
async fn mytask() { let a: i64 = getlocalitem().await.unwrap(0); let msg = format!("The value of a is: {}", a); setlocal_item(msg).await; }
let a: i64 = 3;
let (outext, _) = withextensions(Extensions::new().with(a), mytask()).await;
let msg = outext.get::
Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.