# [−] [src] Struct thread_local::CachedThreadLocal

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

Wrapper around `ThreadLocal` which adds a fast path for a single thread.

This has the same API as `ThreadLocal`, but will register the first thread that sets a value as its owner. All accesses by the owner will go through a special fast path which is much faster than the normal `ThreadLocal` path.

## Methods

### `impl<T: ?Sized + Send> CachedThreadLocal<T>` [src]

#### `pub fn new() -> CachedThreadLocal<T>` [src]

Creates a new empty `CachedThreadLocal`.

#### `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.

#### `pub fn iter_mut(&mut self) -> CachedIterMut<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> CachedThreadLocal<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 CachedThreadLocal<T>` [src]

### `impl<T: ?Sized + Send> Default for CachedThreadLocal<T>` [src]

#### `fn default() -> CachedThreadLocal<T>` [src]

Returns the "default value" for a type. Read more

### `impl<T: ?Sized + Send> IntoIterator for CachedThreadLocal<T>` [src]

#### `type Item = Box<T>`

The type of the elements being iterated over.

#### `type IntoIter = CachedIntoIter<T>`

Which kind of iterator are we turning this into?

#### `fn into_iter(self) -> CachedIntoIter<T>` [src]

Creates an iterator from a value. Read more

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

#### `type Item = &'a mut Box<T>`

The type of the elements being iterated over.

#### `type IntoIter = CachedIterMut<'a, T>`

Which kind of iterator are we turning this into?

#### `fn into_iter(self) -> CachedIterMut<'a, T>` [src]

Creates an iterator from a value. Read more

### `impl<T: ?Sized + Send + Debug> Debug for CachedThreadLocal<T>` [src]

#### `fn fmt(&self, f: &mut Formatter) -> Result` [src]

Formats the value using the given formatter. Read more

### `impl<T: ?Sized + Send + UnwindSafe> UnwindSafe for CachedThreadLocal<T>` [src]

## Auto Trait Implementations

### `impl<T: ?Sized> Send for CachedThreadLocal<T>`

## Blanket Implementations

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

#### `fn from(t: T) -> T` [src]

Performs the conversion.

### `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?

#### `fn into_iter(self) -> I` [src]

Creates an iterator from a value. Read more

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

#### `fn into(self) -> U` [src]

Performs the conversion.

### `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.

#### `fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>` [src]

Performs the conversion.

### `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.

#### `fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>` [src]

Performs the conversion.

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

#### `fn borrow_mut(&mut self) -> &mut T` [src]

Mutably borrows from an owned value. Read more

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

#### `fn borrow(&self) -> &T` [src]

Immutably borrows from an owned value. Read more

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

#### `fn type_id(&self) -> TypeId` [src]

Gets the `TypeId` of `self`. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g., `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g., `vec -> usize` or `* -> vec`)

Search multiple things at once by splitting your query with comma (e.g., `str,u8` or `String,struct:Vec,test`)