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]
impl<'a, T: 'a, C> Queue<'a, T, C>
pub fn apply(&mut self, command: C)
[src]
pub fn apply(&mut self, command: C)
Queues an apply
action.
pub fn undo(&mut self)
[src]
pub fn undo(&mut self)
Queues an undo
action.
pub fn redo(&mut self)
[src]
pub fn redo(&mut self)
Queues a redo
action.
pub fn cancel(self)
[src]
pub fn cancel(self)
Cancels the queued actions.
impl<'a, R, C: Command<R>> Queue<'a, Record<R, C>, C>
[src]
impl<'a, R, C: Command<R>> Queue<'a, Record<R, C>, C>
pub fn go_to(&mut self, cursor: usize)
[src]
pub fn go_to(&mut self, cursor: usize)
Queues a go_to
action.
pub fn commit(self) -> Result<(), Error<R, C>>
[src]
pub fn commit(self) -> Result<(), Error<R, C>>
Applies the actions that is queued.
Errors
If an error occurs, it stops applying the actions and returns the error.
pub fn checkpoint(&mut self) -> Checkpoint<Record<R, C>, C>
[src]
pub fn checkpoint(&mut self) -> Checkpoint<Record<R, C>, C>
Returns a checkpoint.
pub fn queue(&mut self) -> Queue<Record<R, C>, C>
[src]
pub fn queue(&mut self) -> Queue<Record<R, C>, C>
Returns a queue.
pub fn as_receiver(&self) -> &R
[src]
pub fn as_receiver(&self) -> &R
Returns a reference to the receiver
.
pub fn as_mut_receiver(&mut self) -> &mut R
[src]
pub fn as_mut_receiver(&mut self) -> &mut R
Returns a mutable reference to the receiver
.
This method should only be used when doing changes that should not be able to be undone.
impl<'a, R, C: Command<R>> Queue<'a, History<R, C>, C>
[src]
impl<'a, R, C: Command<R>> Queue<'a, History<R, C>, C>
pub fn go_to(&mut self, branch: usize, cursor: usize)
[src]
pub fn go_to(&mut self, branch: usize, cursor: usize)
Queues a go_to
action.
pub fn commit(self) -> Result<(), Error<R, C>>
[src]
pub fn commit(self) -> Result<(), Error<R, C>>
Applies the actions that is queued.
Errors
If an error occurs, it stops applying the actions and returns the error.
pub fn checkpoint(&mut self) -> Checkpoint<History<R, C>, C>
[src]
pub fn checkpoint(&mut self) -> Checkpoint<History<R, C>, C>
Returns a checkpoint.
pub fn queue(&mut self) -> Queue<History<R, C>, C>
[src]
pub fn queue(&mut self) -> Queue<History<R, C>, C>
Returns a queue.
pub fn as_receiver(&self) -> &R
[src]
pub fn as_receiver(&self) -> &R
Returns a reference to the receiver
.
pub fn as_mut_receiver(&mut self) -> &mut R
[src]
pub fn as_mut_receiver(&mut self) -> &mut R
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
impl<'a, T: Debug + 'a, C: Debug> Debug for Queue<'a, T, C>
[src]
impl<'a, T: Debug + 'a, C: Debug> Debug for Queue<'a, T, C>
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl<'a, T: 'a, C> From<&'a mut T> for Queue<'a, T, C>
[src]
impl<'a, T: 'a, C> From<&'a mut T> for Queue<'a, T, C>
impl<'a, R, C: Command<R>> AsRef<R> for Queue<'a, Record<R, C>, C>
[src]
impl<'a, R, C: Command<R>> AsRef<R> for Queue<'a, Record<R, C>, C>
impl<'a, R, C: Command<R>> AsMut<R> for Queue<'a, Record<R, C>, C>
[src]
impl<'a, R, C: Command<R>> AsMut<R> for Queue<'a, Record<R, C>, C>
impl<'a, R, C: Command<R>> AsRef<R> for Queue<'a, History<R, C>, C>
[src]
impl<'a, R, C: Command<R>> AsRef<R> for Queue<'a, History<R, C>, C>
impl<'a, R, C: Command<R>> AsMut<R> for Queue<'a, History<R, C>, C>
[src]
impl<'a, R, C: Command<R>> AsMut<R> for Queue<'a, History<R, C>, C>