pub struct ThreadCell<T: 'static> { /* private fields */ }Expand description
A cell that holds a value bound to a single thread. Thus T can be non-Send and/or non-Sync,
but ThreadCell<T> is always Send/Sync. Access is provided through message passing, so no
internal locking is used. But a lock-like ThreadCellSession can be acquired to gain exclusive
access to the underlying resource while held.
Implementations§
Source§impl<T> ThreadCell<T>
impl<T> ThreadCell<T>
Sourcepub fn new_with<F: FnOnce() -> T + Send + 'static>(resource_fn: F) -> Self
pub fn new_with<F: FnOnce() -> T + Send + 'static>(resource_fn: F) -> Self
Creates a new when T is not Send but a function to create T is
pub fn run_blocking<F, R>(&self, f: F) -> R
pub fn session_blocking(&self) -> ThreadCellSession<T>
Source§impl<T: Send> ThreadCell<T>
impl<T: Send> ThreadCell<T>
Sourcepub fn set_blocking(&self, new_value: T)
pub fn set_blocking(&self, new_value: T)
Set the resource in a blocking manner
Sourcepub fn replace_blocking(&self, new_value: T) -> T
pub fn replace_blocking(&self, new_value: T) -> T
Set the resource in a blocking manner, returning the old value
Source§impl<T: Send + Default> ThreadCell<T>
impl<T: Send + Default> ThreadCell<T>
pub fn take_blocking(&self) -> T
Source§impl<T: Send + Clone> ThreadCell<T>
impl<T: Send + Clone> ThreadCell<T>
Sourcepub fn get_blocking(&self) -> T
pub fn get_blocking(&self) -> T
Get a clone of the resource in a blocking manner
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for ThreadCell<T>
impl<T> RefUnwindSafe for ThreadCell<T>
impl<T> Send for ThreadCell<T>
impl<T> Sync for ThreadCell<T>
impl<T> Unpin for ThreadCell<T>
impl<T> UnwindSafe for ThreadCell<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