pub struct DroppingThreadLocal<T: Send + Sync + 'static> { /* private fields */ }Expand description
A thread local that drops its value when the thread is destroyed.
See module-level documentation for more details.
Dropping this value will free all the associated values.
Implementations§
Source§impl<T: Send + Sync + 'static> DroppingThreadLocal<T>
impl<T: Send + Sync + 'static> DroppingThreadLocal<T>
Sourcepub fn get(&self) -> Option<SharedRef<T>>
pub fn get(&self) -> Option<SharedRef<T>>
Get the value associated with the current thread,
or None if not initialized.
Sourcepub fn set(&self, value: T) -> Result<SharedRef<T>, SharedRef<T>>
pub fn set(&self, value: T) -> Result<SharedRef<T>, SharedRef<T>>
Set the value associated with this thread,
returning an Err(existing_val) if already initialized,
and a reference to the new value if successful.
Sourcepub fn get_or_init(&self, func: impl FnOnce() -> T) -> SharedRef<T>
pub fn get_or_init(&self, func: impl FnOnce() -> T) -> SharedRef<T>
Get the value associated with the current thread, initializing it if not yet defined.
Panics if double initialization is detected.
Sourcepub fn get_or_try_init<E>(
&self,
func: impl FnOnce() -> Result<T, E>,
) -> Result<SharedRef<T>, E>
pub fn get_or_try_init<E>( &self, func: impl FnOnce() -> Result<T, E>, ) -> Result<SharedRef<T>, E>
Get the value associated with the current thread, attempting to initialize it if not yet defined.
Panics if double initialization is detected.
Sourcepub fn snapshot_iter(&self) -> SnapshotIter<T> ⓘ
pub fn snapshot_iter(&self) -> SnapshotIter<T> ⓘ
Iterate over currently live values and their associated thread ids.
New threads that have been spanned after the snapshot was taken will not be present in the iterator. Threads that die after the snapshot is taken may or may not be present. Values from threads that die before the snapshot will not be present.
The order of the iteration is undefined.