Struct ShimTlsVar

Source
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,

Source

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.

Source

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§

Source§

impl<T, F> Sync for ShimTlsVar<'_, T, F>
where F: Sync + Fn() -> T,

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>
where F: Send, T: Send,

§

impl<'tls, T, F> Unpin for ShimTlsVar<'tls, T, F>
where F: Unpin, T: Unpin,

§

impl<'tls, T, F = fn() -> T> !UnwindSafe for ShimTlsVar<'tls, T, F>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> NoTypeInference for T

Source§

type This = T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.