Struct std::thread::local_impl::Key
source · pub struct Key<T> {
os: OsStaticKey,
marker: PhantomData<Cell<T>>,
}
🔬This is a nightly-only experimental API. (
thread_local_internals
)Expand description
Use a regular global static to store this key; the state provided will then be thread-local.
Fields§
§os: OsStaticKey
🔬This is a nightly-only experimental API. (
§thread_local_internals
)marker: PhantomData<Cell<T>>
🔬This is a nightly-only experimental API. (
thread_local_internals
)Implementations§
source§impl<T: 'static> Key<T>
impl<T: 'static> Key<T>
pub fn new() -> Key<T>
🔬This is a nightly-only experimental API. (
thread_local_internals
)sourcepub unsafe fn get(&'static self, init: impl FnOnce() -> T) -> Option<&'static T>
🔬This is a nightly-only experimental API. (thread_local_internals
)
pub unsafe fn get(&'static self, init: impl FnOnce() -> T) -> Option<&'static T>
thread_local_internals
)It is a requirement for the caller to ensure that no mutable reference is active when this method is called.
unsafe fn try_initialize( &'static self, init: impl FnOnce() -> T ) -> Option<&'static T>
🔬This is a nightly-only experimental API. (
thread_local_internals
)Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Key<T>
impl<T> Send for Key<T>where T: Send,
impl<T> Unpin for Key<T>where T: Unpin,
impl<T> !UnwindSafe for Key<T>
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