[−][src]Struct thread_local::CachedThreadLocal
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: 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() -> T,
[src]
F: FnOnce() -> T,
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<T, E>,
[src]
F: FnOnce() -> Result<T, E>,
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 CachedIterMut<'a, T>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_or_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: Send + Debug> Debug for CachedThreadLocal<T>
[src]
impl<T: Send> Default for CachedThreadLocal<T>
[src]
fn default() -> CachedThreadLocal<T>
[src]
impl<T: Send> IntoIterator for CachedThreadLocal<T>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = CachedIntoIter<T>
Which kind of iterator are we turning this into?
ⓘImportant traits for CachedIntoIter<T>fn into_iter(self) -> CachedIntoIter<T>
[src]
impl<'a, T: Send + 'a> IntoIterator for &'a mut CachedThreadLocal<T>
[src]
type Item = &'a mut T
The type of the elements being iterated over.
type IntoIter = CachedIterMut<'a, T>
Which kind of iterator are we turning this into?
ⓘImportant traits for CachedIterMut<'a, T>fn into_iter(self) -> CachedIterMut<'a, T>
[src]
impl<T: Send> Sync for CachedThreadLocal<T>
[src]
impl<T: Send + UnwindSafe> UnwindSafe for CachedThreadLocal<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for CachedThreadLocal<T>
impl<T> Send for CachedThreadLocal<T>
impl<T> Unpin for CachedThreadLocal<T>
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,