Crates.io | backtracking_iterator |
lib.rs | backtracking_iterator |
version | 0.4.4 |
source | src |
created_at | 2018-10-28 12:47:33.571841 |
updated_at | 2019-04-22 12:37:34.470443 |
description | A simple implementation of a generic iterator with an item history, capable of backtracking and forgetting. |
homepage | |
repository | https://github.com/ivanbakel/backtracking_iterator |
max_upload_size | |
id | 93098 |
size | 44,205 |
A wrapper around existing iterators to extend them with backtracking functionality by providing an in-memory history.
In order to create a backtracking iterator on top of an existing iterator, you first wrap it in a BacktrackingRecord
. From there, you have two choices of BacktrackingIterator
:
Copying
, which produces memory clones of the iterator itemsReferencing
, which produces immutable borrows on iterator itemsThe behaviour comes from the BacktrackingIterator
trait.
use backtracking_iterator::{BacktrackingIterator, BacktrackingRecord};
let mut backtracking_record = BacktrackingRecord::new(my_iter);
let mut my_backtracking_iter = backtracking_record.copying();
// Now we can call `next()`, and the result will also be copied
let here = my_backtracking_iter.get_ref_point();
let fresh = my_backtracking_iter.next();
my_backtracking_iter.backtrack(here);
let remembered = my_backtracking_iter.next();
assert!(fresh == remembered);