Struct std::cell::Cell 1.0.0[−][src]
#[repr(transparent)]pub struct Cell<T> where
T: ?Sized, { /* fields omitted */ }
Expand description
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> Cell<T> where
T: Copy, [src]
impl<T> Cell<T> where
T: Copy, [src]impl<T> Cell<T> where
T: ?Sized, [src]
impl<T> Cell<T> where
T: ?Sized, [src]impl<T> Cell<T> where
T: Default, [src]
impl<T> Cell<T> where
T: Default, [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 for Cell<T> where
T: Ord + Copy, 1.10.0[src]
impl<T> Ord for Cell<T> where
T: Ord + Copy, 1.10.0[src]impl<T> PartialOrd<Cell<T>> for Cell<T> where
T: PartialOrd<T> + Copy, 1.10.0[src]
impl<T> PartialOrd<Cell<T>> for Cell<T> where
T: PartialOrd<T> + Copy, 1.10.0[src]pub fn partial_cmp(&self, other: &Cell<T>) -> Option<Ordering>[src]
pub 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
pub fn lt(&self, other: &Cell<T>) -> bool[src]
pub 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
pub fn le(&self, other: &Cell<T>) -> bool[src]
pub 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, U> CoerceUnsized<Cell<U>> for Cell<T> where
T: CoerceUnsized<U>, [src]
T: CoerceUnsized<U>,
impl<T> Eq for Cell<T> where
T: Eq + Copy, 1.2.0[src]
T: Eq + Copy,
impl<T> Send for Cell<T> where
T: Send + ?Sized, [src]
T: Send + ?Sized,
impl<T> !Sync for Cell<T> where
T: ?Sized, [src]
T: ?Sized,
Auto Trait Implementations
impl<T> !RefUnwindSafe for Cell<T>
impl<T: ?Sized> Unpin for Cell<T> where
T: Unpin,
T: Unpin,
impl<T: ?Sized> UnwindSafe for Cell<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]pub fn borrow_mut(&mut self) -> &mut T[src]
pub fn borrow_mut(&mut self) -> &mut T[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone, [src]
impl<T> ToOwned for T where
T: Clone, [src]type Owned = T
type Owned = TThe resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn to_owned(&self) -> T[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)[src]
pub fn clone_into(&self, target: &mut T)[src]🔬 This is a nightly-only experimental API. (toowned_clone_into #41263)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more