Struct memcell::MemoryCell
source · [−]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
sourceimpl<T> MemoryCell<T>
impl<T> MemoryCell<T>
sourcepub fn update(&mut self, new: T)
pub fn update(&mut self, new: T)
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));
sourcepub fn take_current(self) -> T
pub fn take_current(self) -> T
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");
sourcepub fn take_last(self) -> Option<T>
pub fn take_last(self) -> Option<T>
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));
sourcepub fn take_both(self) -> (T, Option<T>)
pub fn take_both(self) -> (T, Option<T>)
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));
sourcepub const fn has_previous(&self) -> bool
pub const fn has_previous(&self) -> bool
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());
sourcepub const fn current(&self) -> &T
pub const fn current(&self) -> &T
Get the current value contained within this MemoryCell
.
use memcell::MemoryCell;
let cell = MemoryCell::new("Joe");
let data = cell.current();
assert_eq!(data, &"Joe");
Trait Implementations
sourceimpl<T: Clone> Clone for MemoryCell<T>
impl<T: Clone> Clone for MemoryCell<T>
sourcefn clone(&self) -> MemoryCell<T>
fn clone(&self) -> MemoryCell<T>
Returns a copy of the value. Read more
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations
impl<T> RefUnwindSafe for MemoryCell<T>where
T: RefUnwindSafe,
impl<T> Send for MemoryCell<T>where
T: Send,
impl<T> Sync for MemoryCell<T>where
T: Sync,
impl<T> Unpin for MemoryCell<T>where
T: Unpin,
impl<T> UnwindSafe for MemoryCell<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more