pub struct Queue<'a, T, C> { /* 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 {
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() -> redo::Result<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(())
}
Implementations
sourceimpl<R, C: Command<R>> Queue<'_, Record<R, C>, C>
impl<R, C: Command<R>> Queue<'_, Record<R, C>, C>
sourcepub fn commit(self) -> Result<R, C>
pub fn commit(self) -> Result<R, C>
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, C>, C>
pub fn checkpoint(&mut self) -> Checkpoint<'_, Record<R, C>, C>
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.
sourceimpl<R, C: Command<R>> Queue<'_, History<R, C>, C>
impl<R, C: Command<R>> Queue<'_, History<R, C>, C>
sourcepub fn commit(self) -> Result<R, C>
pub fn commit(self) -> Result<R, C>
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, C>, C>
pub fn checkpoint(&mut self) -> Checkpoint<'_, History<R, C>, C>
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.
Trait Implementations
Auto Trait Implementations
impl<'a, T, C> RefUnwindSafe for Queue<'a, T, C>where
C: RefUnwindSafe,
T: RefUnwindSafe,
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,
impl<'a, T, C> Unpin for Queue<'a, T, C>where
C: Unpin,
impl<'a, T, C> !UnwindSafe for Queue<'a, T, C>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more