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]
impl<'a, T: 'a, R> Queue<'a, T, R>pub fn apply(
&mut self,
command: impl Command<R> + 'static
)[src]
pub fn apply(
&mut self,
command: impl Command<R> + 'static
)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> Queue<'a, Record<R>, R>[src]
impl<'a, R> Queue<'a, Record<R>, R>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>> where
R: 'static, [src]
pub fn commit(self) -> Result<(), Error<R>> where
R: 'static, 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>, R>[src]
pub fn checkpoint(&mut self) -> Checkpoint<Record<R>, R>Returns a checkpoint.
pub fn queue(&mut self) -> Queue<Record<R>, R>[src]
pub fn queue(&mut self) -> Queue<Record<R>, R>Returns a queue.
pub fn as_receiver(&self) -> &R[src]
pub fn as_receiver(&self) -> &RReturns a reference to the receiver.
pub fn as_mut_receiver(&mut self) -> &mut R[src]
pub fn as_mut_receiver(&mut self) -> &mut RReturns 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> Queue<'a, History<R>, R>[src]
impl<'a, R> Queue<'a, History<R>, R>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>> where
R: 'static, [src]
pub fn commit(self) -> Result<(), Error<R>> where
R: 'static, 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>, R>[src]
pub fn checkpoint(&mut self) -> Checkpoint<History<R>, R>Returns a checkpoint.
pub fn queue(&mut self) -> Queue<History<R>, R>[src]
pub fn queue(&mut self) -> Queue<History<R>, R>Returns a queue.
pub fn as_receiver(&self) -> &R[src]
pub fn as_receiver(&self) -> &RReturns a reference to the receiver.
pub fn as_mut_receiver(&mut self) -> &mut R[src]
pub fn as_mut_receiver(&mut self) -> &mut RReturns 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, R: Debug> Debug for Queue<'a, T, R>[src]
impl<'a, T: Debug + 'a, R: Debug> Debug for Queue<'a, T, R>fn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl<'a, T: 'a, R> From<&'a mut T> for Queue<'a, T, R>[src]
impl<'a, T: 'a, R> From<&'a mut T> for Queue<'a, T, R>impl<'a, R> AsRef<R> for Queue<'a, Record<R>, R>[src]
impl<'a, R> AsRef<R> for Queue<'a, Record<R>, R>impl<'a, R> AsMut<R> for Queue<'a, Record<R>, R>[src]
impl<'a, R> AsMut<R> for Queue<'a, Record<R>, R>impl<'a, R> AsRef<R> for Queue<'a, History<R>, R>[src]
impl<'a, R> AsRef<R> for Queue<'a, History<R>, R>impl<'a, R> AsMut<R> for Queue<'a, History<R>, R>[src]
impl<'a, R> AsMut<R> for Queue<'a, History<R>, R>