rust-context

Crates.iorust-context
lib.rsrust-context
version0.1.0
sourcesrc
created_at2023-07-04 10:11:12.375775
updated_at2023-07-04 10:11:12.375775
descriptionA macro for using threadlocals to deeply bind contextual values
homepage
repository
max_upload_size
id907866
size4,874
Fábio Santos (fabiosantoscode)

documentation

README

rust-deep-bind

rust-deep-bind helps you bind a value to any function you call, without explicitly passing it through an argument.

You might use this to hold on to configuration, a request or operation ID, or anything for which you would like to use a singleton, but are concerned about all problems that come about with global state.

Example:

contextual!{
    MyCounter(MY_COUNTER): u32 = 0
}

println!("{}", MyCounter::clone()); /// 0
MyCounter::replace_within(1, || {
    println!("{}", MyCounter::clone()); /// 1
});
println!("{}", MyCounter::clone()); /// 0
Commit count: 0

cargo fmt