Struct thread_local::CachedThreadLocal [] [src]

pub struct CachedThreadLocal<T: ?Sized + Send> {
    // some 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]

fn new() -> CachedThreadLocal<T>

Creates a new empty CachedThreadLocal.

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> CachedThreadLocal<T>
[src]

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 CachedThreadLocal<T>
[src]

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

fn default() -> CachedThreadLocal<T>

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