contrail 0.0.1

Primitives and collections stored on an undoable trail.
docs.rs failed to build contrail-0.0.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Visit the last successful build: contrail-0.3.0

Build Status

contrail

Usage

Add this to your Cargo.toml:

[dependencies]
contrail = "0.1"

Example usage:

extern crate contrail;

use contrail::{Stored, TrailBuilder, Trailed};

fn main() {
    // setup the trail
    let mut builder = TrailBuilder::new();
    let trailed_counter = Trailed::new(&mut builder, 0);
    let stored_counter = Stored::new(&mut builder, 0);
    let mut trail = builder.finish();

    // push a new level onto the trail
    trail.new_level();

    // increment each counter
    trailed_counter.update(&mut trail, |x| x + 1);
    stored_counter.update(&mut trail, |x| x + 1);
    assert_eq!(trailed_counter.get(&trail), 1);
    assert_eq!(stored_counter.get(&trail), 1);

    // pop the previous level from the trail
    trail.undo_level();

    // the trailed counter is reset to its value when new_level() was called
    // the stored counter is unchanged
    assert_eq!(trailed_counter.get(&trail), 0);
    assert_eq!(stored_counter.get(&trail), 1);
}