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§
source§impl<'a, R> Queue<'a, Record<R>, R>
impl<'a, R> Queue<'a, Record<R>, R>
sourcepub fn commit(self) -> Result<R>where
R: 'static,
pub fn commit(self) -> Result<R>where
R: 'static,
Applies the actions that is queued.
Errors
If an error occurs, it stops applying the actions and returns the error.
sourcepub fn checkpoint(&mut self) -> Checkpoint<'_, Record<R>, R>
pub fn checkpoint(&mut self) -> Checkpoint<'_, Record<R>, R>
Returns a checkpoint.
sourcepub fn as_receiver(&self) -> &R
pub fn as_receiver(&self) -> &R
Returns a reference to the receiver
.
sourcepub fn as_mut_receiver(&mut self) -> &mut R
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.
source§impl<'a, R> Queue<'a, History<R>, R>
impl<'a, R> Queue<'a, History<R>, R>
sourcepub fn commit(self) -> Result<R>where
R: 'static,
pub fn commit(self) -> Result<R>where
R: 'static,
Applies the actions that is queued.
Errors
If an error occurs, it stops applying the actions and returns the error.
sourcepub fn checkpoint(&mut self) -> Checkpoint<'_, History<R>, R>
pub fn checkpoint(&mut self) -> Checkpoint<'_, History<R>, R>
Returns a checkpoint.
sourcepub fn as_receiver(&self) -> &R
pub fn as_receiver(&self) -> &R
Returns a reference to the receiver
.
sourcepub fn as_mut_receiver(&mut self) -> &mut R
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.