Expand description
§scoped-thread-local
Flexible version of thread local
Features
- Lifetime elision in declaration (every elided lifetime becomes a distinct one)
- Full HKT Supports
§License
MIT OR Apache-2.0
§Example
See example
module for expanded code
/// Container type for scoped thread local variable
pub struct Container<'a, 'b> {
pub a: &'a i32,
pub b: &'b i32,
}
crate::scoped_thread_local!(
/// Generated scoped thread local variable.
///
/// Elided lifetimes are also supported.
pub static EXAMPLE: for<'a> Container<'a, '_>
);
fn main() {
EXAMPLE.set(
&mut Container {
a: &1,
b: &2,
},
|| {
EXAMPLE.with(|inner| {
// Prints 3
println!("{}", *inner.a + *inner.b);
});
},
);
}
Modules§
- example
example
- Expanded example code
Macros§
- scoped_
thread_ local - Create scoped thread local