Crates.io | restorable |
lib.rs | restorable |
version | 0.2.0 |
source | src |
created_at | 2019-10-03 11:46:47.791813 |
updated_at | 2019-10-05 01:42:30.697783 |
description | An iterator adapter for saving and restoring iterator state |
homepage | |
repository | https://github.com/BlueBlazin/restorable |
max_upload_size | |
id | 169606 |
size | 19,844 |
This is ideal for writing lexers and parsers where backtracking may be required.
use restorable::RestorableIter;
#[test]
fn test_restorable_new() {
let mut iterator = RestorableIter::new(0..4);
assert_eq!(iterator.next(), Some(0));
assert_eq!(iterator.next(), Some(1));
iterator.save();
assert_eq!(iterator.next(), Some(2));
assert_eq!(iterator.next(), Some(3));
iterator.restore();
assert_eq!(iterator.next(), Some(2));
assert_eq!(iterator.next(), Some(3));
assert_eq!(iterator.next(), None);
}
use restorable::Restorable;
#[test]
fn test_iter_restorable() {
let mut iterator = (0..4).iter_restorable();
assert_eq!(iterator.next(), Some(0));
assert_eq!(iterator.next(), Some(1));
iterator.save();
assert_eq!(iterator.next(), Some(2));
assert_eq!(iterator.next(), Some(3));
iterator.restore();
assert_eq!(iterator.next(), Some(2));
assert_eq!(iterator.next(), Some(3));
assert_eq!(iterator.next(), None);
}
Add restorable
under [dependecies]
with the appropriate version number in your cargo.toml.
[dependencies]
restorable = "^MAJOR.MINOR"
0.2.0 - Added clear
to stop saving and clear the buffer.