Struct undo::Queue

source ·
pub struct Queue<'a, T: 'a, R> { /* private fields */ }
Expand description

A command queue wrapper.

Wraps a Record or History and gives it batch queue functionality.

Examples

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

impl Command<String> for Add {
    fn apply(&mut self, s: &mut String) -> Result<(), Box<dyn Error + Send + Sync>> {
        s.push(self.0);
        Ok(())
    }

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

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

Implementations§

Queues an apply action.

Queues an undo action.

Queues a redo action.

Cancels the queued actions.

Queues a go_to action.

Applies the actions that is queued.

Errors

If an error occurs, it stops applying the actions and returns the error.

Returns a checkpoint.

Returns a queue.

Returns a reference to the receiver.

Returns a mutable reference to the receiver.

This method should only be used when doing changes that should not be able to be undone.

Queues a go_to action.

Applies the actions that is queued.

Errors

If an error occurs, it stops applying the actions and returns the error.

Returns a checkpoint.

Returns a queue.

Returns a reference to the receiver.

Returns a mutable reference to the receiver.

This method should only be used when doing changes that should not be able to be undone.

Trait Implementations§

Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Formats the value using the given formatter. Read more
Converts to this type from the input type.

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.