Crates.io | ambience |
lib.rs | ambience |
version | 0.2.1 |
source | src |
created_at | 2020-04-09 18:49:46.156394 |
updated_at | 2020-04-14 15:15:11.746616 |
description | Lightweight library for passing ambient parameters |
homepage | |
repository | https://github.com/vlthr/ambience |
max_upload_size | |
id | 228065 |
size | 12,057 |
A lightweight library for passing ambient parameters.
Thread-local ambient parameters can be set with ambience::thread::set
. The ambient parameter can then be accessed via ambience::thread::get
until the guard object returned by set
is dropped.
struct User {
// ...
}
fn process() {
// retrieve the user from this threads ambient environment
let user: Rc<User> = ambience::thread::get::<User>();
// ...
}
fn main() {
let user = // ...
// set the user as ambient data for the current thread.
// the value is accessible until `_ambience_guard` is dropped.
let _ambience_guard = ambience::thread::set::<User>(user);
process();
}