transactional_iterator 0.1.0

Iterator that allows to commit or abort progress.
Documentation

Transactional Iterator

A Transaction can be used to make changes to an iterator and only apply the changes if the transaction is committed. When the Transaction is aborted, the changes are discarded. This is useful for implementing backtracking searches, parsers, undo functionality and more.

The original iterator must implement 'Clone' to be useable with the transactional iterator. Transactions must be either committed or aborted, just dropping them will cause in a panic.

Example

use transactional_iterator::Transaction;

let mut iter = vec![1, 2, 3].into_iter();
let mut transaction = Transaction::new(&mut iter);

// iterate within the transaction
assert_eq!(transaction.next(), Some(1));
assert_eq!(transaction.next(), Some(2));

// Commit the transaction
transaction.commit();

// The changes are now applied
assert_eq!(iter.next(), Some(3));