Struct lrs::share::Cell

A container with interior mutability.

Syntax

struct Cell<T> {
    data: T,
}

Fields

NameDescription
data

The data contained in the cell.

Static methods

NameDescription
new

Creates a new cell.

Methods

ReceiverNameDescription
&selfptr

Returns a mutable pointer to the data.

Trait implementations

NameDescription
Copy

Objects that can safely be copied via memcpy.

Sync

Objects that allow immutable access from threads other than their owning thread.

Remarks

Modifying data through immutable & references is undefined behavior unless the data is (recursively) contained in a Cell.

This type is not Sync because race conditions are undefined behavior. It should rarely be used directly except to build more robust structures with interior mutability such as CopyCell.

Examples

struct X {
    val: Cell<i32>,
}

impl X {
    fn modify(&self, new: i32) {
        unsafe { *self.val.ptr() = new; }
    }
}