backtracking_iterator

Crates.iobacktracking_iterator
lib.rsbacktracking_iterator
version0.4.4
sourcesrc
created_at2018-10-28 12:47:33.571841
updated_at2019-04-22 12:37:34.470443
descriptionA simple implementation of a generic iterator with an item history, capable of backtracking and forgetting.
homepage
repositoryhttps://github.com/ivanbakel/backtracking_iterator
max_upload_size
id93098
size44,205
(ivanbakel)

documentation

README

Backtracking Iterators

Documentation status

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 items
  • Referencing, which produces immutable borrows on iterator items

The behaviour comes from the BacktrackingIterator trait.

Example

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);
Commit count: 29

cargo fmt