Struct per_thread_object::ThreadLocal
source · pub struct ThreadLocal<T: Send + 'static> { /* private fields */ }
Expand description
Per-object thread-local storage
Capacity
per-thread-object
has no max capacity limit,
each ThreadLocal
instance will create its own memory space
instead of using global space.
this crate supports any number of threads, but only the DEFAULT_PAGE_CAP threads are lock-free.
Panic when dropping
ThreadLocal
will release object at the end of thread.
If panic occurs during this process, it may cause a memory leak.
Implementations
sourceimpl<T: Send + 'static> ThreadLocal<T>
impl<T: Send + 'static> ThreadLocal<T>
pub fn new() -> ThreadLocal<T>
pub fn get<'stack>(&'stack self, _token: &'stack StackToken) -> Option<&'stack T>
pub fn get_or_init<'stack, F>(
&'stack self,
token: &'stack StackToken,
init: F
) -> &'stack Twhere
F: FnOnce() -> T,
pub fn get_or_try_init<'stack, F, E>(
&'stack self,
_token: &'stack StackToken,
init: F
) -> Result<&'stack T, E>where
F: FnOnce() -> Result<T, E>,
Trait Implementations
sourceimpl<T: Send + 'static> Default for ThreadLocal<T>
impl<T: Send + 'static> Default for ThreadLocal<T>
sourcefn default() -> ThreadLocal<T>
fn default() -> ThreadLocal<T>
Returns the “default value” for a type. Read more
impl<T: Send> Send for ThreadLocal<T>
impl<T: Send> Sync for ThreadLocal<T>
Auto Trait Implementations
impl<T> !RefUnwindSafe for ThreadLocal<T>
impl<T> Unpin for ThreadLocal<T>
impl<T> UnwindSafe for ThreadLocal<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more