A container with interior mutability.
struct Cell<T> {
data: T,
}| Name | Description |
|---|---|
| data | The data contained in the cell. |
| Name | Description |
|---|---|
| new | Creates a new cell. |
| Receiver | Name | Description |
|---|---|---|
&self | ptr | Returns a mutable pointer to the data. |
| Name | Description |
|---|---|
| Copy | Objects that can safely be copied via |
| Sync | Objects that allow immutable access from threads other than their owning thread. |
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.
struct X {
val: Cell<i32>,
}
impl X {
fn modify(&self, new: i32) {
unsafe { *self.val.ptr() = new; }
}
}