Struct thread_local::ThreadLocal
[−]
[src]
pub struct ThreadLocal<T: ?Sized + Send> { // some fields omitted }
Thread-local variable wrapper
See the module-level documentation for more.
Methods
impl<T: ?Sized + Send> ThreadLocal<T>
fn new() -> ThreadLocal<T>
Creates a new empty ThreadLocal
.
fn get(&self) -> Option<&T>
Returns the element for the current thread, if it exists.
fn get_or<F>(&self, create: F) -> &T where F: FnOnce() -> Box<T>
Returns the element for the current thread, or creates it if it doesn't exist.
fn iter_mut(&mut self) -> IterMut<T>
Returns a mutable iterator over the local values of all threads.
Since this call borrows the ThreadLocal
mutably, this operation can
be done safely---the mutable borrow statically guarantees no other
threads are currently accessing their associated values.
fn clear(&mut self)
Removes all thread-specific values from the ThreadLocal
, effectively
reseting it to its original state.
Since this call borrows the ThreadLocal
mutably, this operation can
be done safely---the mutable borrow statically guarantees no other
threads are currently accessing their associated values.
impl<T: Send + Default> ThreadLocal<T>
fn get_default(&self) -> &T
Returns the element for the current thread, or creates a default one if it doesn't exist.