[][src]Struct thread_local::ThreadLocal

pub struct ThreadLocal<T: ?Sized + Send> { /* fields omitted */ }

Thread-local variable wrapper

See the module-level documentation for more.

Methods

impl<T: ?Sized + Send> ThreadLocal<T>[src]

pub fn new() -> ThreadLocal<T>[src]

Creates a new empty ThreadLocal.

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() -> Box<T>, 
[src]

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<Box<T>, E>, 
[src]

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.

Important traits for IterMut<'a, T>
pub fn iter_mut(&mut self) -> IterMut<T>[src]

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.

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_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: ?Sized + Send> Sync for ThreadLocal<T>[src]

impl<T: ?Sized + Send> Default for ThreadLocal<T>[src]

impl<T: ?Sized + Send> IntoIterator for ThreadLocal<T>[src]

type Item = Box<T>

The type of the elements being iterated over.

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?

impl<'a, T: ?Sized + Send + 'a> IntoIterator for &'a mut ThreadLocal<T>[src]

type Item = &'a mut Box<T>

The type of the elements being iterated over.

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?

impl<T: ?Sized + Send> Drop for ThreadLocal<T>[src]

impl<T: ?Sized + Send + Debug> Debug for ThreadLocal<T>[src]

impl<T: ?Sized + Send + UnwindSafe> UnwindSafe for ThreadLocal<T>[src]

Auto Trait Implementations

impl<T: ?Sized> Send for ThreadLocal<T>

Blanket Implementations

impl<T> From<T> for T[src]

impl<I> IntoIterator for I where
    I: Iterator
[src]

type Item = <I as Iterator>::Item

The type of the elements being iterated over.

type IntoIter = I

Which kind of iterator are we turning this into?

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]