pub struct ShimTlsVar<'tls, T, F = fn() -> T>where
F: Fn() -> T,{ /* private fields */ }
Expand description
Thread local storage for a variable of type T
, initialized on first access
by each thread using a function of type F
.
The Drop
implementation of T
is not called, e.g. when threads exit or
this value itself is dropped.
Implementations§
Source§impl<'tls, T, F> ShimTlsVar<'tls, T, F>where
F: Fn() -> T,
impl<'tls, T, F> ShimTlsVar<'tls, T, F>where
F: Fn() -> T,
Sourcepub const fn new(tls: &'tls ThreadLocalStorage, f: F) -> Self
pub const fn new(tls: &'tls ThreadLocalStorage, f: F) -> Self
Create a variable that will be uniquely instantiated for each thread,
initialized with f
on first access by each thread.
Typically this should go in a static
.
Sourcepub fn get<'var>(&'var self) -> TlsVarRef<'tls, 'var, T, F>
pub fn get<'var>(&'var self) -> TlsVarRef<'tls, 'var, T, F>
Access the inner value.
The returned wrapper can’t be sent to or shared with other threads,
since the underlying storage is invalidated when the originating thread
calls ThreadLocalStorage::unregister_current_thread
.
Trait Implementations§
Auto Trait Implementations§
impl<'tls, T, F = fn() -> T> !Freeze for ShimTlsVar<'tls, T, F>
impl<'tls, T, F = fn() -> T> !RefUnwindSafe for ShimTlsVar<'tls, T, F>
impl<'tls, T, F> Send for ShimTlsVar<'tls, T, F>
impl<'tls, T, F> Unpin for ShimTlsVar<'tls, T, F>
impl<'tls, T, F = fn() -> T> !UnwindSafe for ShimTlsVar<'tls, T, F>
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