Struct core::cell::Cell 1.0.0[−][src]
#[repr(transparent)]pub struct Cell<T: ?Sized> { /* fields omitted */ }
A mutable memory location.
Examples
In this example, you can see that Cell<T> enables mutation inside an
immutable struct. In other words, it enables “interior mutability”.
use std::cell::Cell; struct SomeStruct { regular_field: u8, special_field: Cell<u8>, } let my_struct = SomeStruct { regular_field: 0, special_field: Cell::new(1), }; let new_value = 100; // ERROR: `my_struct` is immutable // my_struct.regular_field = new_value; // WORKS: although `my_struct` is immutable, `special_field` is a `Cell`, // which can always be mutated my_struct.special_field.set(new_value); assert_eq!(my_struct.special_field.get(), new_value);Run
See the module-level documentation for more.
Implementations
impl<T> Cell<T>[src]
impl<T> Cell<T>[src]impl<T: Copy> Cell<T>[src]
impl<T: Copy> Cell<T>[src]impl<T: ?Sized> Cell<T>[src]
impl<T: ?Sized> Cell<T>[src]impl<T: Default> Cell<T>[src]
impl<T: Default> Cell<T>[src]impl<T> Cell<[T]>[src]
impl<T> Cell<[T]>[src]pub fn as_slice_of_cells(&self) -> &[Cell<T>]1.37.0[src]
pub fn as_slice_of_cells(&self) -> &[Cell<T>]1.37.0[src]Trait Implementations
impl<T: Ord + Copy> Ord for Cell<T>1.10.0[src]
impl<T: Ord + Copy> Ord for Cell<T>1.10.0[src]#[must_use]fn max(self, other: Self) -> Self where
Self: Sized, 1.21.0[src]
#[must_use]fn max(self, other: Self) -> Self where
Self: Sized, 1.21.0[src]Compares and returns the maximum of two values. Read more
impl<T: PartialOrd + Copy> PartialOrd<Cell<T>> for Cell<T>1.10.0[src]
impl<T: PartialOrd + Copy> PartialOrd<Cell<T>> for Cell<T>1.10.0[src]fn partial_cmp(&self, other: &Cell<T>) -> Option<Ordering>[src]
fn partial_cmp(&self, other: &Cell<T>) -> Option<Ordering>[src]This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Cell<T>) -> bool[src]
fn lt(&self, other: &Cell<T>) -> bool[src]This method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Cell<T>) -> bool[src]
fn le(&self, other: &Cell<T>) -> bool[src]This method tests less than or equal to (for self and other) and is used by the <=
operator. Read more
impl<T: CoerceUnsized<U>, U> CoerceUnsized<Cell<U>> for Cell<T>[src]
impl<T: Eq + Copy> Eq for Cell<T>1.2.0[src]
impl<T: ?Sized> Send for Cell<T> where
T: Send, [src]
T: Send,