Macro thread_local
macro_rules! thread_local {
() => { ... };
($($tt:tt)+) => { ... };
}
Declare a new thread local storage key of type std::thread::LocalKey.
Syntax
The macro wraps any number of static declarations and makes them thread local. Publicity and attributes for each static are allowed. Example:
use ;
thread_local!
assert_eq!;
BAR.with_borrow;
Note that only shared references (&T) to the inner data may be obtained, so a
type such as Cell or RefCell is typically used to allow mutating access.
This macro supports a special const {} syntax that can be used
when the initialization expression can be evaluated as a constant.
This can enable a more efficient thread local implementation that
can avoid lazy initialization. For types that do not
[need to be dropped][crate::mem::needs_drop], this can enable an
even more efficient implementation that does not need to
track any additional state.
use RefCell;
thread_local!
FOO.with_borrow;
See LocalKey documentation for more
information.