ambience 0.2.1

Lightweight library for passing ambient parameters
Documentation
  • Coverage
  • 41.67%
    5 out of 12 items documented0 out of 6 items with examples
  • Size
  • Source code size: 12.05 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 568.62 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 14s Average build duration of successful builds.
  • all releases: 14s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • vlthr/ambience
    7 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • vlthr

Ambience

A lightweight library for passing ambient parameters.

Examples

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();
}