Struct thread_local::ThreadLocal [−][src]
Thread-local variable wrapper
See the module-level documentation for more.
Implementations
impl<T: Send> ThreadLocal<T>
[src]
pub fn new() -> ThreadLocal<T>
[src]
Creates a new empty ThreadLocal
.
pub fn with_capacity(capacity: usize) -> ThreadLocal<T>
[src]
Creates a new ThreadLocal
with an initial capacity. If less than the capacity threads
access the thread local it will never reallocate. The capacity may be rounded up to the
nearest power of two.
pub fn get(&self) -> Option<&T>
[src]
Returns the element for the current thread, if it exists.
pub fn get_or<F>(&self, create: F) -> &T where
F: FnOnce() -> T,
[src]
F: FnOnce() -> T,
Returns the element for the current thread, or creates it if it doesn’t exist.
pub fn get_or_try<F, E>(&self, create: F) -> Result<&T, E> where
F: FnOnce() -> Result<T, E>,
[src]
F: FnOnce() -> Result<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.
pub fn iter(&self) -> Iter<'_, T>ⓘ where
T: Sync,
[src]
T: Sync,
Returns an iterator over the local values of all threads in unspecified order.
This call can be done safely, as T
is required to implement Sync
.
pub fn iter_mut(&mut self) -> IterMut<'_, T>ⓘ
[src]
Returns a mutable iterator over the local values of all threads in unspecified order.
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.
pub fn clear(&mut self)
[src]
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>
[src]
pub fn get_or_default(&self) -> &T
[src]
Returns the element for the current thread, or creates a default one if it doesn’t exist.
Trait Implementations
impl<T: Send + Debug> Debug for ThreadLocal<T>
[src]
impl<T: Send> Default for ThreadLocal<T>
[src]
fn default() -> ThreadLocal<T>
[src]
impl<T: Send> Drop for ThreadLocal<T>
[src]
impl<T: Send> IntoIterator for ThreadLocal<T>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IntoIter<T>ⓘ
[src]
impl<'a, T: Send + Sync> IntoIterator for &'a ThreadLocal<T>
[src]
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T: Send> IntoIterator for &'a mut ThreadLocal<T>
[src]
type Item = &'a mut T
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IterMut<'a, T>ⓘ
[src]
impl<T: Send> Sync for ThreadLocal<T>
[src]
impl<T: Send + UnwindSafe> UnwindSafe for ThreadLocal<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for ThreadLocal<T>
impl<T> Send for ThreadLocal<T>
impl<T> Unpin for ThreadLocal<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,