2 releases
0.1.1 | Oct 16, 2022 |
---|---|
0.1.0 | Oct 14, 2022 |
#1718 in Data structures
7KB
51 lines
memcell
What is a MemoryCell?
A MemoryCell
is a struct containing both a current and optional previous value.
Definition
#[derive(Debug, Clone)]
pub struct MemoryCell<T> {
current: T,
last_val: Option<T>,
}
Features
- Full documentation
- Constant methods
- Lightweight
- Zero dependencies
- Pure Rust
Example Usage
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));
}
lib.rs
:
What is a [MemoryCell]?
A MemoryCell
is a struct containing both a current and optional previous value.
Definition
#[derive(Debug, Clone)]
pub struct MemoryCell<T> {
current: T,
last_val: Option<T>,
}
Example usage
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));