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

A cell containing a value ([T]), and the last (previous) value stored in the cell.

Examples

use memcell::MemoryCell;

let mut cell = MemoryCell::new(5_u32);

let new_value = 10;
cell.update(new_value);

assert_eq!(cell.current(), &10);
assert_eq!(cell.last(), &Some(5));

Implementations

Set the current value as the last value, then set the current value to the given argument.

use memcell::MemoryCell;

let mut cell = MemoryCell::new(5_u32);

let new_value = 10;
cell.update(new_value);

assert_eq!(cell.current(), &10);
assert_eq!(cell.last(), &Some(5));

Take the current value contained within this MemoryCell.

use memcell::MemoryCell;

let cell = MemoryCell::new("Joe");
let data = cell.take_current();

assert_eq!(data, "Joe");

Take the previous value contained within this MemoryCell.

use memcell::MemoryCell;

let mut cell = MemoryCell::new(5);
cell.update(10);

assert_eq!(cell.take_last(), Some(5));

Take both the current and last value of this MemoryCell and return them in a tuple.

use memcell::MemoryCell;

let mut cell = MemoryCell::new(5);

cell.update(10);

let (new, old) = cell.take_both();

assert_eq!(new, 10);
assert_eq!(old, Some(5));

Get whether this MemoryCell contains a previous value.

use memcell::MemoryCell;

let mut cell = MemoryCell::new(5);

assert!(!cell.has_previous());

cell.update(10);

assert!(cell.has_previous());

Get the current value contained within this MemoryCell.

use memcell::MemoryCell;

let cell = MemoryCell::new("Joe");
let data = cell.current();

assert_eq!(data, &"Joe");

Get the last value contained in this MemoryCell.

use memcell::MemoryCell;

let mut cell = MemoryCell::new(5);
cell.update(10);

assert_eq!(cell.last(), &Some(5));

Create a new MemoryCell with the given value.

Create a new MemoryCell containing the given previous value.

Trait Implementations

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more

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

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