pub struct CachedThreadLocal<T>where
T: Send,{ /* private fields */ }ThreadLocal insteadExpand description
Wrapper around ThreadLocal.
This used to add a fast path for a single thread, however that has been
obsoleted by performance improvements to ThreadLocal itself.
Implementationsยง
Sourceยงimpl<T> CachedThreadLocal<T>where
T: Send,
impl<T> CachedThreadLocal<T>where
T: Send,
Sourcepub fn new() -> CachedThreadLocal<T>
pub fn new() -> CachedThreadLocal<T>
Creates a new empty CachedThreadLocal.
Sourcepub fn get_or<F>(&self, create: F) -> &Twhere
F: FnOnce() -> T,
pub fn get_or<F>(&self, create: F) -> &Twhere
F: FnOnce() -> T,
Returns the element for the current thread, or creates it if it doesnโt exist.
Sourcepub fn get_or_try<F, E>(&self, create: F) -> Result<&T, E>
pub fn get_or_try<F, E>(&self, create: F) -> 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.
Sourcepub fn iter_mut(&mut self) -> CachedIterMut<'_, T> โ
pub fn iter_mut(&mut self) -> CachedIterMut<'_, T> โ
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.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
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.
Sourceยงimpl<T> CachedThreadLocal<T>
impl<T> CachedThreadLocal<T>
Sourcepub fn get_or_default(&self) -> &T
pub fn get_or_default(&self) -> &T
Returns the element for the current thread, or creates a default one if it doesnโt exist.
Trait Implementationsยง
Sourceยงimpl<T> Debug for CachedThreadLocal<T>
impl<T> Debug for CachedThreadLocal<T>
Sourceยงimpl<T> Default for CachedThreadLocal<T>where
T: Send,
impl<T> Default for CachedThreadLocal<T>where
T: Send,
Sourceยงfn default() -> CachedThreadLocal<T>
fn default() -> CachedThreadLocal<T>
Sourceยงimpl<'a, T> IntoIterator for &'a mut CachedThreadLocal<T>where
T: Send + 'a,
impl<'a, T> IntoIterator for &'a mut CachedThreadLocal<T>where
T: Send + 'a,
Sourceยงimpl<T> IntoIterator for CachedThreadLocal<T>where
T: Send,
impl<T> IntoIterator for CachedThreadLocal<T>where
T: Send,
impl<T> UnwindSafe for CachedThreadLocal<T>where
T: Send + UnwindSafe,
Auto Trait Implementationsยง
impl<T> !Freeze for CachedThreadLocal<T>
impl<T> RefUnwindSafe for CachedThreadLocal<T>
impl<T> Send for CachedThreadLocal<T>
impl<T> Sync for CachedThreadLocal<T>
impl<T> Unpin for CachedThreadLocal<T>
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Sourceยงimpl<T> Instrument for T
impl<T> Instrument for T
Sourceยงfn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Sourceยงfn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more