Module std::local_data[src]
Task local data management
Allows storing arbitrary types inside task-local-storage (TLS), to be accessed anywhere within a task, keyed by a global pointer parameterized over the type of the TLS slot. Useful for dynamic variables, singletons, and interfacing with foreign code with bad callback interfaces.
To declare a new key for storing local data of a particular type, use the
local_data_key! macro. This macro will expand to a static item appropriately
named and annotated. This name is then passed to the functions in this module to
modify/read the slot specified by the key.
local_data_key!(key_int: int) local_data_key!(key_vector: Vec<int>) key_int.replace(Some(3)); assert_eq!(*key_int.get().unwrap(), 3); key_vector.replace(Some(vec![4])); assert_eq!(*key_vector.get().unwrap(), vec![4]);
Structs
| Ref | An RAII immutable reference to a task-local value. |
Enums
| KeyValue |
Type Definitions
| Key | |
| Map |