Struct redo::Queue[][src]

pub struct Queue<'a, T: 'a, C> { /* 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 {
    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 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, C> Queue<'a, T, C>
[src]

Queues an apply action.

Queues an undo action.

Queues a redo action.

Cancels the queued actions.

impl<'a, R, C: Command<R>> Queue<'a, Record<R, C>, C>
[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, C: Command<R>> Queue<'a, History<R, C>, C>
[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, C: Debug> Debug for Queue<'a, T, C>
[src]

Formats the value using the given formatter. Read more

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

Auto Trait Implementations

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

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