Crates.io | rust-context |
lib.rs | rust-context |
version | 0.1.0 |
source | src |
created_at | 2023-07-04 10:11:12.375775 |
updated_at | 2023-07-04 10:11:12.375775 |
description | A macro for using threadlocals to deeply bind contextual values |
homepage | |
repository | |
max_upload_size | |
id | 907866 |
size | 4,874 |
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