pub struct ThreadMap<V> { /* private fields */ }Expand description
This type encapsulates the association of ThreadIds to values of type V. It is a simple and easy-to-use alternative
to the std::thread_local macro and the thread_local crate.
Implementations§
Source§impl<V> ThreadMap<V>
impl<V> ThreadMap<V>
Sourcepub fn new(value_init: fn() -> V) -> Self
pub fn new(value_init: fn() -> V) -> Self
Creates a new ThreadMap instance, with value_init used to create the initial value for each thread.
Sourcepub fn drain(&self) -> Result<HashMap<ThreadId, V>, ThreadMapLockError>
pub fn drain(&self) -> Result<HashMap<ThreadId, V>, ThreadMapLockError>
Returns a HashMap with the values associated with each ThreadId key and clears self’s state.
§Errors
ThreadMapLockErrorif the internal lock is poisoned.
Sourcepub fn fold<W>(
&self,
z: W,
f: impl FnMut(W, (ThreadId, &V)) -> W,
) -> Result<W, ThreadMapLockError>
pub fn fold<W>( &self, z: W, f: impl FnMut(W, (ThreadId, &V)) -> W, ) -> Result<W, ThreadMapLockError>
Folds every association in self into an accumulator (with initial value z) by applying an operation f,
returning the final result.
§Errors
ThreadMapLockErrorif the internal lock is poisoned.
Sourcepub fn fold_values<W>(
&self,
z: W,
f: impl FnMut(W, &V) -> W,
) -> Result<W, ThreadMapLockError>
pub fn fold_values<W>( &self, z: W, f: impl FnMut(W, &V) -> W, ) -> Result<W, ThreadMapLockError>
Folds every value in self into an accumulator (with initial value z) by applying an operation f,
returning the final result.
§Errors
ThreadMapLockErrorif the internal lock is poisoned.
Trait Implementations§
Auto Trait Implementations§
impl<V> !Freeze for ThreadMap<V>
impl<V> RefUnwindSafe for ThreadMap<V>
impl<V> Send for ThreadMap<V>where
V: Send,
impl<V> Sync for ThreadMap<V>where
V: Send,
impl<V> Unpin for ThreadMap<V>where
V: Unpin,
impl<V> UnwindSafe for ThreadMap<V>
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
Mutably borrows from an owned value. Read more