Struct redo::Checkpoint[][src]

pub struct Checkpoint<'a, T: 'a, C> { /* fields omitted */ }

A checkpoint wrapper.

Wraps a Record or History and gives it checkpoint functionality.

Examples

#[derive(Debug)]
struct Add(char);

impl Command<String> for Add {
    type Error = Box<dyn error::Error>;

    fn apply(&mut self, s: &mut String) -> Result<(), Self::Error> {
        s.push(self.0);
        Ok(())
    }

    fn undo(&mut self, s: &mut String) -> Result<(), Self::Error> {
        self.0 = s.pop().ok_or("`s` is empty")?;
        Ok(())
    }
}

fn main() -> Result<(), Error<String, Add>> {
    let mut record = Record::default();
    {
        let mut cp = record.checkpoint();
        cp.apply(Add('a'))?;
        cp.apply(Add('b'))?;
        cp.apply(Add('c'))?;
        assert_eq!(cp.as_receiver(), "abc");
        cp.cancel()?;
    }
    assert_eq!(record.as_receiver(), "");
    Ok(())
}

Methods

impl<'a, R, C: Command<R>> Checkpoint<'a, Record<R, C>, C>
[src]

Calls the apply method.

Calls the undo method.

Calls the redo method.

Calls the go_to method.

Commits the changes and consumes the checkpoint.

Cancels the changes and consumes the checkpoint.

Errors

If an error occur when canceling the changes, the error is returned together with the command.

Returns a checkpoint.

Returns a queue.

Returns a reference to the receiver.

impl<'a, R, C: Command<R>> Checkpoint<'a, History<R, C>, C>
[src]

Calls the apply method.

Calls the undo method.

Calls the redo method.

Calls the go_to method.

Commits the changes and consumes the checkpoint.

Cancels the changes and consumes the checkpoint.

Errors

If an error occur when canceling the changes, the error is returned together with the command.

Returns a checkpoint.

Returns a queue.

Returns a reference to the receiver.

Trait Implementations

impl<'a, T: Debug + 'a, C: Debug> Debug for Checkpoint<'a, T, C>
[src]

Formats the value using the given formatter. Read more

impl<'a, T: 'a, C> From<&'a mut T> for Checkpoint<'a, T, C>
[src]

Performs the conversion.

impl<'a, R, C: Command<R>> AsRef<R> for Checkpoint<'a, Record<R, C>, C>
[src]

Performs the conversion.

impl<'a, R, C: Command<R>> AsRef<R> for Checkpoint<'a, History<R, C>, C>
[src]

Performs the conversion.

Auto Trait Implementations

impl<'a, T, C> Send for Checkpoint<'a, T, C> where
    C: Send,
    T: Send

impl<'a, T, C> Sync for Checkpoint<'a, T, C> where
    C: Sync,
    T: Sync