[−][src]Struct alloc_tls::TLSSlot
A slot for a thread-local variable.
A TLSSlot
should be initialized using the internal_thread_local!
macro. See its
documentation for details on declaring and using thread-local variables.
Methods
impl<T> TLSSlot<T>
[src]
pub unsafe fn with<R, F: FnOnce(&T) -> R>(&self, f: F) -> Option<R>
[src]
Access the TLS slot.
with
accepts a function that will be called with a reference to the TLS value. If the
slot is in the initializing or dropped state, with
will return None
without
invoking f
. If the slot is in the uninitialized state, with
will initialize the value
and then call f
. If the slot is in the initialized state, with
will call f
. In
either of these last two cases, with
will return Some(r)
, where r
is the value
returned from the call to f
.
Safety
with
is unsafe because if f
panics, it causes undefined behavior.
Trait Implementations
Auto Trait Implementations
impl<T> !RefUnwindSafe for TLSSlot<T>
impl<T> !Send for TLSSlot<T>
impl<T> Unpin for TLSSlot<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for TLSSlot<T> where
T: RefUnwindSafe + UnwindSafe,
T: RefUnwindSafe + UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,