Struct undo::RecordBuilder[][src]

pub struct RecordBuilder<R> { /* fields omitted */ }

Builder for a record.

Methods

impl<R> RecordBuilder<R>
[src]

Sets the specified capacity for the record.

Sets the limit for the record.

If this limit is reached it will start popping of commands at the beginning of the record when pushing new commands on to the stack. No limit is set by default which means it may grow indefinitely.

Examples

let mut record = Record::builder()
    .capacity(2)
    .limit(2)
    .default();

record.apply(Add('a'))?;
record.apply(Add('b'))?;
record.apply(Add('c'))?; // 'a' is removed from the record since limit is 2.

assert_eq!(record.as_receiver(), "abc");

record.undo().unwrap()?;
record.undo().unwrap()?;
assert!(record.undo().is_none());

assert_eq!(record.into_receiver(), "a");

Panics

Panics if limit is 0.

Sets if the receiver is initially in a saved state.

Decides how the signal should be handled when the state changes. By default the record does nothing.

Examples

Record::builder()
    .signal(|signal| {
        match signal {
            Signal::Undo(true) => println!("The record can undo."),
            Signal::Undo(false) => println!("The record can not undo."),
            Signal::Redo(true) => println!("The record can redo."),
            Signal::Redo(false) => println!("The record can not redo."),
            Signal::Saved(true) => println!("The receiver is in a saved state."),
            Signal::Saved(false) => println!("The receiver is not in a saved state."),
            Signal::Cursor { old, new } => {
                println!("The current command has changed from {} to {}.", old, new);
            },
            _ => {},
        }
    })
    .default();

Creates the record.

impl<R: Default> RecordBuilder<R>
[src]

Creates the record with a default receiver.

Trait Implementations

impl<R: Debug> Debug for RecordBuilder<R>
[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<R> Send for RecordBuilder<R> where
    R: Send

impl<R> Sync for RecordBuilder<R> where
    R: Sync