Struct threadcell::ThreadCell
source · [−]pub struct ThreadCell<T> { /* private fields */ }Expand description
A cell that can be owned by a single thread or none at all.
Implementations
sourceimpl<T> ThreadCell<T>
impl<T> ThreadCell<T>
sourcepub const fn new_disowned(data: T) -> Self
pub const fn new_disowned(data: T) -> Self
Creates a ThreadCell that is not owned by any thread. This is a const fn which
allows static construction of ThreadCells.
sourcepub fn acquire(&self)
pub fn acquire(&self)
Takes the ownership of a cell. This is a no-op when the cell is already owned by the current thread.
Panics
When the cell is owned by another thread.
sourcepub fn try_acquire(&self) -> bool
pub fn try_acquire(&self) -> bool
Tries to take the ownership of a cell. Returns true when the ownership could be obtained or the cell was already owned by the current thread and false when the cell is owned by another thread.
sourcepub fn acquire_get(&self) -> &T
pub fn acquire_get(&self) -> &T
Takes the ownership of a cell and returns a reference to its value.
Panics
When the cell is owned by another thread.
sourcepub fn try_acquire_get(&self) -> Option<&T>
pub fn try_acquire_get(&self) -> Option<&T>
Tries to take the ownership of a cell and returns a reference to its value. Will return ‘None’ when the cell is owned by another thread.
sourcepub fn acquire_get_mut(&mut self) -> &mut T
pub fn acquire_get_mut(&mut self) -> &mut T
Takes the ownership of a cell and returns a mutable reference to its value.
Panics
When the cell is owned by another thread.
sourcepub fn try_acquire_get_mut(&mut self) -> Option<&mut T>
pub fn try_acquire_get_mut(&mut self) -> Option<&mut T>
Tries to take the ownership of a cell and returns a mutable reference to its value. Will return ‘None’ when the cell is owned by another thread.
sourcepub unsafe fn steal(&self)
pub unsafe fn steal(&self)
Takes the ownership of a cell unconditionally. This is a no-op when the cell is already owned by the current thread.
Safety
This method does not check if the cell is owned by another thread. The owning thread may operate on the content, thus a data race/UB will happen when the accessed value is not Sync. The previous owning thread may panic when it expects owning the cell. The only safe way to use this method is to recover a cell that is owned by a thread that finished without releasing it (e.g after a panic).
sourcepub fn release(&self)
pub fn release(&self)
Sets a ThreadCell which is owned by the current thread into the disowned state.
Panics
The current thread does not own the cell.
sourcepub fn try_release(&self) -> bool
pub fn try_release(&self) -> bool
Tries to set a ThreadCell which is owned by the current thread into the disowned
state. Returns true on success and false when the current thread does not own the
cell.
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
sourcepub fn try_get(&self) -> Option<&T>
pub fn try_get(&self) -> Option<&T>
Tries to get an immutable reference to the cells content. Returns ‘None’ when the thread does not own the cell.
sourcepub fn try_get_mut(&mut self) -> Option<&mut T>
pub fn try_get_mut(&mut self) -> Option<&mut T>
Tries to get a mutable reference to the cells content. Returns ‘None’ when the thread does not own the cell.
sourcepub unsafe fn get_unchecked(&self) -> &T
pub unsafe fn get_unchecked(&self) -> &T
Gets an immutable reference to the cells content without checking for ownership.
Safety
This is always safe when the thread owns the cell, for example right after a
get_ownership() call. When the current thread does not own the cell then it is only
safe when T is a Sync type.
sourcepub unsafe fn get_mut_unchecked(&mut self) -> &mut T
pub unsafe fn get_mut_unchecked(&mut self) -> &mut T
Gets an mutable reference to the cells content without checking for ownership.
Safety
This is always safe when the thread owns the cell, for example right after a
get_ownership() call. When the current thread does not own the cell then it is only
safe when T is a Sync type.
Trait Implementations
sourceimpl<T: Clone> Clone for ThreadCell<T>
impl<T: Clone> Clone for ThreadCell<T>
sourcefn clone(&self) -> ThreadCell<T>
fn clone(&self) -> ThreadCell<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source. Read more
sourceimpl<T: Debug> Debug for ThreadCell<T>
impl<T: Debug> Debug for ThreadCell<T>
Debug information of a ThreadCell.
Prints “<invalid thread>” when the current thread does not own the cell.
sourceimpl<T: Default> Default for ThreadCell<T>
impl<T: Default> Default for ThreadCell<T>
Creates a new owned ThreadCell with the default constructed target value.
sourcefn default() -> ThreadCell<T>
fn default() -> ThreadCell<T>
Returns the “default value” for a type. Read more
sourceimpl<T: Display> Display for ThreadCell<T>
impl<T: Display> Display for ThreadCell<T>
Formatted output of the value inside a ThreadCell.
Panics
The cell is not owned by the current thread.
sourceimpl<T> Drop for ThreadCell<T>
impl<T> Drop for ThreadCell<T>
Destroys a ThreadCell. The cell must be either owned by the current thread or disowned.
Panics
Another thread owns the cell.
sourceimpl<T> From<T> for ThreadCell<T>
impl<T> From<T> for ThreadCell<T>
Creates a new owned ThreadCell from the given value.
sourcefn from(t: T) -> ThreadCell<T>
fn from(t: T) -> ThreadCell<T>
Converts to this type from the input type.
sourceimpl<T: Ord> Ord for ThreadCell<T>
impl<T: Ord> Ord for ThreadCell<T>
sourcefn cmp(&self, other: &ThreadCell<T>) -> Ordering
fn cmp(&self, other: &ThreadCell<T>) -> Ordering
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Self where
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl<T: PartialEq> PartialEq<ThreadCell<T>> for ThreadCell<T>
impl<T: PartialEq> PartialEq<ThreadCell<T>> for ThreadCell<T>
sourcefn eq(&self, other: &ThreadCell<T>) -> bool
fn eq(&self, other: &ThreadCell<T>) -> bool
This method tests for self and other values to be equal, and is used
by ==. Read more
sourceimpl<T: PartialOrd> PartialOrd<ThreadCell<T>> for ThreadCell<T>
impl<T: PartialOrd> PartialOrd<ThreadCell<T>> for ThreadCell<T>
sourcefn partial_cmp(&self, other: &ThreadCell<T>) -> Option<Ordering>
fn partial_cmp(&self, other: &ThreadCell<T>) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
sourcefn lt(&self, other: &ThreadCell<T>) -> bool
fn lt(&self, other: &ThreadCell<T>) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
sourcefn le(&self, other: &ThreadCell<T>) -> bool
fn le(&self, other: &ThreadCell<T>) -> bool
This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
sourcefn gt(&self, other: &ThreadCell<T>) -> bool
fn gt(&self, other: &ThreadCell<T>) -> bool
This method tests greater than (for self and other) and is used by the > operator. Read more
sourcefn ge(&self, other: &ThreadCell<T>) -> bool
fn ge(&self, other: &ThreadCell<T>) -> bool
This method tests greater than or equal to (for self and other) and is used by the >=
operator. Read more
impl<T: Eq> Eq for ThreadCell<T>
impl<T> Send for ThreadCell<T>
Safety
This type is meant for sending values that are !Send to other threads.
impl<T> Sync for ThreadCell<T>
Safety
Only the owning thread can access the value or release ownership. The ThreadCell itself
can be shared between threads (for acquiring ownership etc). Ownership handling done by
atomic primitives.
Auto Trait Implementations
impl<T> RefUnwindSafe for ThreadCell<T> where
T: RefUnwindSafe,
impl<T> Unpin for ThreadCell<T> where
T: Unpin,
impl<T> UnwindSafe for ThreadCell<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
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