pub struct ThreadLocal<T: 'static> { /* private fields */ }Expand description
A thread local variable wrapper.
Implementations§
Source§impl<T: 'static> ThreadLocal<T>
impl<T: 'static> ThreadLocal<T>
Sourcepub fn new() -> ThreadLocal<T>
pub fn new() -> ThreadLocal<T>
Creates a new ThreadLocal with no values for any threads.
§Panics
Panics if more than usize::max_value() ThreadLocal objects have already been created.
This can only ever realistically happen on 32 bit platforms.
Sourcepub fn set(&self, value: T) -> Option<T>
pub fn set(&self, value: T) -> Option<T>
Sets this thread’s value, returning the previous value if present.
§Panics
Panics if called from within the execution of a closure provided to another method on this value.
Sourcepub fn remove(&self) -> Option<T>
pub fn remove(&self) -> Option<T>
Removes this thread’s value, returning it if it existed.
§Panics
Panics if called from within the execution of a closure provided to another method on this value.
Sourcepub fn entry<F, R>(&self, f: F) -> R
pub fn entry<F, R>(&self, f: F) -> R
Passes a handle to the current thread’s value to a closure for in-place manipulation.
The closure is required for the same soundness reasons it is required for the standard
library’s thread_local! values.
§Panics
Panics if called from within the execution of a closure provided to another method on this value.
Sourcepub fn get<F, R>(&self, f: F) -> R
pub fn get<F, R>(&self, f: F) -> R
Passes a mutable reference to the current thread’s value to a closure.
The closure is required for the same soundness reasons it is required for the standard
library’s thread_local! values.
§Panics
Panics if called from within the execution of a closure passed to entry or get_mut on
this value.
Sourcepub fn get_mut<F, R>(&self, f: F) -> R
pub fn get_mut<F, R>(&self, f: F) -> R
Passes a mutable reference to the current thread’s value to a closure.
The closure is required for the same soundness reasons it is required for the standard
library’s thread_local! values.
§Panics
Panics if called from within the execution of a closure provided to another method on this value.
Source§impl<T> ThreadLocal<T>where
T: 'static + Clone,
impl<T> ThreadLocal<T>where
T: 'static + Clone,
Sourcepub fn get_cloned(&self) -> Option<T>
pub fn get_cloned(&self) -> Option<T>
Returns a copy of the current thread’s value.
§Panics
Panics if called from within the execution of a closure passed to entry or get_mut on
this value.