backtracking_iterator 0.4.4

A simple implementation of a generic iterator with an item history, capable of backtracking and forgetting.
Documentation

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);