Struct thread_local::ThreadLocal
source · [−]Expand description
Thread-local variable wrapper
See the module-level documentation for more.
Implementations
sourceimpl<T: ?Sized + Send> ThreadLocal<T>
impl<T: ?Sized + Send> ThreadLocal<T>
sourcepub fn new() -> ThreadLocal<T>
pub fn new() -> ThreadLocal<T>
Creates a new empty ThreadLocal.
sourcepub fn get_or<F>(&self, create: F) -> &Twhere
F: FnOnce() -> Box<T>,
pub fn get_or<F>(&self, create: F) -> &Twhere
F: FnOnce() -> Box<T>,
Returns the element for the current thread, or creates it if it doesn’t exist.
sourcepub fn get_or_try<F, E>(&self, create: F) -> Result<&T, E>where
F: FnOnce() -> Result<Box<T>, E>,
pub fn get_or_try<F, E>(&self, create: F) -> Result<&T, E>where
F: FnOnce() -> Result<Box<T>, E>,
Returns the element for the current thread, or creates it if it doesn’t
exist. If create fails, that error is returned and no element is
added.
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T>ⓘNotable traits for IterMut<'a, T>impl<'a, T: ?Sized + Send + 'a> Iterator for IterMut<'a, T> type Item = &'a mut Box<T>;
pub fn iter_mut(&mut self) -> IterMut<'_, T>ⓘNotable traits for IterMut<'a, T>impl<'a, T: ?Sized + Send + 'a> Iterator for IterMut<'a, T> type Item = &'a mut Box<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.
sourcepub fn clear(&mut self)
pub 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.
sourceimpl<T: Send + Default> ThreadLocal<T>
impl<T: Send + Default> ThreadLocal<T>
sourcepub fn get_default(&self) -> &T
pub fn get_default(&self) -> &T
Returns the element for the current thread, or creates a default one if it doesn’t exist.