Struct undo::Checkpoint [−][src]
pub struct Checkpoint<'a, T: 'a, R> { /* 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 { 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 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> Checkpoint<'a, Record<R>, R>
[src]
impl<'a, R> Checkpoint<'a, Record<R>, R>
pub fn apply(
&mut self,
command: impl Command<R> + 'static
) -> Result<(), Error<R>> where
R: 'static,
[src]
pub fn apply(
&mut self,
command: impl Command<R> + 'static
) -> Result<(), Error<R>> where
R: 'static,
Calls the apply
method.
pub fn undo(&mut self) -> Option<Result<(), Error<R>>>
[src]
pub fn undo(&mut self) -> Option<Result<(), Error<R>>>
Calls the undo
method.
pub fn redo(&mut self) -> Option<Result<(), Error<R>>>
[src]
pub fn redo(&mut self) -> Option<Result<(), Error<R>>>
Calls the redo
method.
pub fn go_to(&mut self, cursor: usize) -> Option<Result<(), Error<R>>>
[src]
pub fn go_to(&mut self, cursor: usize) -> Option<Result<(), Error<R>>>
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>>
[src]
pub fn cancel(self) -> Result<(), Error<R>>
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>, 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) -> &R
Returns a reference to the receiver
.
impl<'a, R> Checkpoint<'a, History<R>, R>
[src]
impl<'a, R> Checkpoint<'a, History<R>, R>
pub fn apply(
&mut self,
command: impl Command<R> + 'static
) -> Result<(), Error<R>> where
R: 'static,
[src]
pub fn apply(
&mut self,
command: impl Command<R> + 'static
) -> Result<(), Error<R>> where
R: 'static,
Calls the apply
method.
pub fn undo(&mut self) -> Option<Result<(), Error<R>>>
[src]
pub fn undo(&mut self) -> Option<Result<(), Error<R>>>
Calls the undo
method.
pub fn redo(&mut self) -> Option<Result<(), Error<R>>>
[src]
pub fn redo(&mut self) -> Option<Result<(), Error<R>>>
Calls the redo
method.
pub fn go_to(
&mut self,
branch: usize,
cursor: usize
) -> Option<Result<(), Error<R>>> where
R: 'static,
[src]
pub fn go_to(
&mut self,
branch: usize,
cursor: usize
) -> Option<Result<(), Error<R>>> where
R: 'static,
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>> where
R: 'static,
[src]
pub fn cancel(self) -> Result<(), Error<R>> where
R: 'static,
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>, 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) -> &R
Returns a reference to the receiver
.
Trait Implementations
impl<'a, T: Debug + 'a, R: Debug> Debug for Checkpoint<'a, T, R>
[src]
impl<'a, T: Debug + 'a, R: Debug> Debug for Checkpoint<'a, T, R>
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, R> From<&'a mut T> for Checkpoint<'a, T, R>
[src]
impl<'a, T: 'a, R> From<&'a mut T> for Checkpoint<'a, T, R>
impl<'a, R> AsRef<R> for Checkpoint<'a, Record<R>, R>
[src]
impl<'a, R> AsRef<R> for Checkpoint<'a, Record<R>, R>
impl<'a, R> AsRef<R> for Checkpoint<'a, History<R>, R>
[src]
impl<'a, R> AsRef<R> for Checkpoint<'a, History<R>, R>
Auto Trait Implementations
impl<'a, T, R> Send for Checkpoint<'a, T, R> where
T: Send,
impl<'a, T, R> Send for Checkpoint<'a, T, R> where
T: Send,
impl<'a, T, R> Sync for Checkpoint<'a, T, R> where
T: Sync,
impl<'a, T, R> Sync for Checkpoint<'a, T, R> where
T: Sync,