Struct undo::Queue[][src]

pub struct Queue<'a, T: 'a, R> { /* fields omitted */ }

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() -> Result<(), Box<dyn Error>> {
    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(())
}

Methods

impl<'a, T: 'a, R> Queue<'a, T, R>
[src]

Queues an apply action.

Queues an undo action.

Queues a redo action.

Cancels the queued actions.

impl<'a, R> Queue<'a, Record<R>, R>
[src]

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.

impl<'a, R> Queue<'a, History<R>, R>
[src]

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.

Trait Implementations

impl<'a, T: Debug + 'a, R: Debug> Debug for Queue<'a, T, R>
[src]

Formats the value using the given formatter. Read more

impl<'a, T: 'a, R> From<&'a mut T> for Queue<'a, T, R>
[src]

Performs the conversion.

impl<'a, R> AsRef<R> for Queue<'a, Record<R>, R>
[src]

Performs the conversion.

impl<'a, R> AsRef<R> for Queue<'a, History<R>, R>
[src]

Performs the conversion.

Auto Trait Implementations

impl<'a, T, R> Send for Queue<'a, T, R> where
    T: Send

impl<'a, T, R> Sync for Queue<'a, T, R> where
    T: Sync