Struct redo::Checkpoint [−][src]
pub struct Checkpoint<'a, T: 'a, C> { /* fields omitted */ }
A checkpoint wrapper.
Wraps a Record or History and gives it checkpoint 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 cp = record.checkpoint(); cp.apply(Add('a'))?; cp.apply(Add('b'))?; cp.apply(Add('c'))?; assert_eq!(cp.as_receiver(), "abc"); cp.cancel()?; } assert_eq!(record.as_receiver(), ""); Ok(()) }
Methods
impl<'a, R, C: Command<R>> Checkpoint<'a, Record<R, C>, C>
[src]
impl<'a, R, C: Command<R>> Checkpoint<'a, Record<R, C>, C>
pub fn apply(&mut self, command: C) -> Result<(), Error<R, C>>
[src]
pub fn apply(&mut self, command: C) -> Result<(), Error<R, C>>
Calls the apply
method.
pub fn undo(&mut self) -> Option<Result<(), Error<R, C>>>
[src]
pub fn undo(&mut self) -> Option<Result<(), Error<R, C>>>
Calls the undo
method.
pub fn redo(&mut self) -> Option<Result<(), Error<R, C>>>
[src]
pub fn redo(&mut self) -> Option<Result<(), Error<R, C>>>
Calls the redo
method.
pub fn go_to(&mut self, cursor: usize) -> Option<Result<(), Error<R, C>>>
[src]
pub fn go_to(&mut self, cursor: usize) -> Option<Result<(), Error<R, C>>>
Calls the go_to
method.
pub fn commit(self)
[src]
pub fn commit(self)
Commits the changes and consumes the checkpoint.
pub fn cancel(self) -> Result<(), Error<R, C>>
[src]
pub fn cancel(self) -> Result<(), Error<R, C>>
Cancels the changes and consumes the checkpoint.
Errors
If an error occur when canceling the changes, the error is returned together with the command.
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>> Checkpoint<'a, History<R, C>, C>
[src]
impl<'a, R, C: Command<R>> Checkpoint<'a, History<R, C>, C>
pub fn apply(&mut self, command: C) -> Result<(), Error<R, C>>
[src]
pub fn apply(&mut self, command: C) -> Result<(), Error<R, C>>
Calls the apply
method.
pub fn undo(&mut self) -> Option<Result<(), Error<R, C>>>
[src]
pub fn undo(&mut self) -> Option<Result<(), Error<R, C>>>
Calls the undo
method.
pub fn redo(&mut self) -> Option<Result<(), Error<R, C>>>
[src]
pub fn redo(&mut self) -> Option<Result<(), Error<R, C>>>
Calls the redo
method.
pub fn go_to(
&mut self,
branch: usize,
cursor: usize
) -> Option<Result<(), Error<R, C>>>
[src]
pub fn go_to(
&mut self,
branch: usize,
cursor: usize
) -> Option<Result<(), Error<R, C>>>
Calls the go_to
method.
pub fn commit(self)
[src]
pub fn commit(self)
Commits the changes and consumes the checkpoint.
pub fn cancel(self) -> Result<(), Error<R, C>>
[src]
pub fn cancel(self) -> Result<(), Error<R, C>>
Cancels the changes and consumes the checkpoint.
Errors
If an error occur when canceling the changes, the error is returned together with the command.
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 Checkpoint<'a, T, C>
[src]
impl<'a, T: Debug + 'a, C: Debug> Debug for Checkpoint<'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 Checkpoint<'a, T, C>
[src]
impl<'a, T: 'a, C> From<&'a mut T> for Checkpoint<'a, T, C>
impl<'a, R, C: Command<R>> AsRef<R> for Checkpoint<'a, Record<R, C>, C>
[src]
impl<'a, R, C: Command<R>> AsRef<R> for Checkpoint<'a, Record<R, C>, C>
impl<'a, R, C: Command<R>> AsMut<R> for Checkpoint<'a, Record<R, C>, C>
[src]
impl<'a, R, C: Command<R>> AsMut<R> for Checkpoint<'a, Record<R, C>, C>
impl<'a, R, C: Command<R>> AsRef<R> for Checkpoint<'a, History<R, C>, C>
[src]
impl<'a, R, C: Command<R>> AsRef<R> for Checkpoint<'a, History<R, C>, C>
impl<'a, R, C: Command<R>> AsMut<R> for Checkpoint<'a, History<R, C>, C>
[src]
impl<'a, R, C: Command<R>> AsMut<R> for Checkpoint<'a, History<R, C>, C>
Auto Trait Implementations
impl<'a, T, C> Send for Checkpoint<'a, T, C> where
C: Send,
T: Send,
impl<'a, T, C> Send for Checkpoint<'a, T, C> where
C: Send,
T: Send,
impl<'a, T, C> Sync for Checkpoint<'a, T, C> where
C: Sync,
T: Sync,
impl<'a, T, C> Sync for Checkpoint<'a, T, C> where
C: Sync,
T: Sync,