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

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

## Trait Implementations

### `impl<T: ?Sized + Send> Sync for ThreadLocal<T>`

### `impl<T: ?Sized + Send> Default for ThreadLocal<T>`

#### `fn default() -> ThreadLocal<T>`

### `impl<T: ?Sized + Send> Drop for ThreadLocal<T>`

#### `fn drop(&mut self)`

# Help

## Keyboard Shortcuts

?
  Show this help dialog
S
  Focus the search field
⇤
  Move up in search results
⇥
  Move down in search results
⏎
  Go to active search result

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