transactional_iterator 0.4.0

Iterator that allows to commit or abort progress.
Documentation
  • Coverage
  • 100%
    25 out of 25 items documented18 out of 25 items with examples
  • Size
  • Source code size: 24.01 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.82 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 11s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • cehteh

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 rolled back, the changes are discarded. This is useful for implementing backtracking searches, parsers, undo functionality, unlimited peeking and more.

The original iterator must implement 'Clone' to be useable with the transactional iterator.

Policies

Transactions can be created with 3 different policies:

  • Panic:
    Will panic on drop if not committed or rolled back.
  • Rollback:
    Will rollback changes on drop or panic.
  • AutoCommit:
    Will commit changes on drop or panic.

Example

use transactional_iterator::{Transaction, Panic};

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

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