Crates.io | memcell |
lib.rs | memcell |
version | 0.1.1 |
source | src |
created_at | 2022-10-14 02:33:03.051421 |
updated_at | 2022-10-16 15:35:51.983575 |
description | A crate providing a MemoryCell struct, which stores a current and previous value. |
homepage | |
repository | https://github.com/ImajinDevon/memcell |
max_upload_size | |
id | 687879 |
size | 8,654 |
A MemoryCell
is a struct containing both a current and optional previous value.
#[derive(Debug, Clone)]
pub struct MemoryCell<T> {
current: T,
last_val: Option<T>,
}
use memcell::MemoryCell;
fn main() {
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));
}