thread_scoped_ref
A library that is similar to a thread local storage but allows to store references / dyn Trait within a scope. It can be used to 'inject' references (if you don't own the data) into functions you don't control (e.g. functions from an external library).
Cargo
[]
= "0"
More information
See crates.io, the documentation and the tests.
Example
use ;
/// Declare the `REF_TO_A_STRING`.
thread_scoped_ref!;
/// This function reads the value and prints the value. This function is usually called by an external
/// library you don't control.
// Example #1: prints `There's no string` (since not called within a scope).
value_consumer;
// Example #2: With a scope.
let my_string = "The String!".to_string;
// note: We use the reference and not the actual string. It's not static!
let my_string_ref = &my_string;
scoped;
// Example #3: Nested scopes.
let another_string = "Another string".to_string;
scoped;
// Example #4: No scope (like example 1). prints `There's no string`.
value_consumer;
License
MIT OR Apache-2.0