pub struct ThreadCell<T> { /* private fields */ }
Expand description

A cell that can be owned by a single thread or none at all.

Implementations

Creates a ThreadCell that is not owned by any thread. This is a const fn which allows static construction of ThreadCells.

Creates a ThreadCell that is owned by the current thread.

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.

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.

Takes the ownership of a cell and returns a reference to its value.

Panics

When the cell is owned by another thread.

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.

Takes the ownership of a cell and returns a mutable reference to its value.

Panics

When the cell is owned by another thread.

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.

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).

Sets a ThreadCell which is owned by the current thread into the disowned state.

Panics

The current thread does not own the cell.

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.

Returns true when the current thread owns this cell.

Consumes a owned cell and returns its content.

Panics

The current thread does not own the cell.

Gets an immutable reference to the cells content.

Panics

The current thread does not own the cell.

Gets a mutable reference to the cells content.

Panics

The current thread does not own the cell.

Tries to get an immutable reference to the cells content. Returns ‘None’ when the thread does not own the cell.

Tries to get a mutable reference to the cells content. Returns ‘None’ when the thread does not own the cell.

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.

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

Clones a owned ThreadCell.

Panics

Another thread owns the cell.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Debug information of a ThreadCell. Prints “<invalid thread>” when the current thread does not own the cell.

Formats the value using the given formatter. Read more

Creates a new owned ThreadCell with the default constructed target value.

Returns the “default value” for a type. Read more

Formatted output of the value inside a ThreadCell.

Panics

The cell is not owned by the current thread.

Formats the value using the given formatter. Read more

Destroys a ThreadCell. The cell must be either owned by the current thread or disowned.

Panics

Another thread owns the cell.

Executes the destructor for this type. Read more

Creates a new owned ThreadCell from the given value.

Converts to this type from the input type.

Compare two ThreadCells.

Panics

Either cell is not owned by the current thread.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

Check two ThreadCells for partial equality.

Panics

Either cell is not owned by the current thread.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Comparison functions between ThreadCells.

Panics

Either cell is not owned by the current thread.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Safety

This type is meant for sending values that are !Send to other threads.

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

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.