[−][src]Struct undo::Checkpoint
A checkpoint wrapper.
Wraps a record or history and gives it checkpoint functionality. This allows the record or history to cancel all changes made since creating the checkpoint.
Examples
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(), "");
Methods
impl<'a, T, R> Checkpoint<'a, T, R>
[src]
pub fn new(inner: &'a mut T) -> Checkpoint<'a, T, R>
[src]
Returns a checkpoint.
pub fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional
more commands in the checkpoint.
Panics
Panics if the new capacity overflows usize.
pub fn capacity(&self) -> usize
[src]
Returns the capacity of the checkpoint.
pub fn shrink_to_fit(&mut self)
[src]
Shrinks the capacity of the checkpoint as much as possible.
pub fn len(&self) -> usize
[src]
Returns the number of commands in the checkpoint.
pub fn is_empty(&self) -> bool
[src]
Returns true
if the checkpoint is empty.
pub fn commit(self)
[src]
Commits the changes and consumes the checkpoint.
impl<'_, R> Checkpoint<'_, Record<R>, R>
[src]
pub fn apply(&mut self, command: impl Command<R> + 'static) -> Result where
R: 'static,
[src]
R: 'static,
Calls the apply
method.
pub fn undo(&mut self) -> Option<Result>
[src]
Calls the undo
method.
pub fn redo(&mut self) -> Option<Result>
[src]
Calls the redo
method.
pub fn go_to(&mut self, current: usize) -> Option<Result>
[src]
Calls the go_to
method.
pub fn extend<C: Command<R> + 'static>(
&mut self,
commands: impl IntoIterator<Item = C>
) -> Result where
R: 'static,
[src]
&mut self,
commands: impl IntoIterator<Item = C>
) -> Result where
R: 'static,
Calls the extend
method.
pub fn cancel(self) -> Result
[src]
Cancels the changes and consumes the checkpoint.
Errors
If an error occur when canceling the changes, the error is returned and the remaining commands are not canceled.
pub fn checkpoint(&mut self) -> Checkpoint<Record<R>, R>
[src]
Returns a checkpoint.
pub fn queue(&mut self) -> Queue<Record<R>, R>
[src]
Returns a queue.
pub fn as_receiver(&self) -> &R
[src]
Returns a reference to the receiver
.
pub fn as_mut_receiver(&mut self) -> &mut R
[src]
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<'_, R> Checkpoint<'_, History<R>, R>
[src]
pub fn apply(&mut self, command: impl Command<R> + 'static) -> Result where
R: 'static,
[src]
R: 'static,
Calls the apply
method.
pub fn undo(&mut self) -> Option<Result>
[src]
Calls the undo
method.
pub fn redo(&mut self) -> Option<Result>
[src]
Calls the redo
method.
pub fn go_to(&mut self, branch: usize, current: usize) -> Option<Result> where
R: 'static,
[src]
R: 'static,
Calls the go_to
method.
pub fn extend<C: Command<R> + 'static>(
&mut self,
commands: impl IntoIterator<Item = C>
) -> Result where
R: 'static,
[src]
&mut self,
commands: impl IntoIterator<Item = C>
) -> Result where
R: 'static,
Calls the extend
method.
pub fn cancel(self) -> Result where
R: 'static,
[src]
R: 'static,
Cancels the changes and consumes the checkpoint.
Errors
If an error occur when canceling the changes, the error is returned and the remaining commands are not canceled.
pub fn checkpoint(&mut self) -> Checkpoint<History<R>, R>
[src]
Returns a checkpoint.
pub fn queue(&mut self) -> Queue<History<R>, R>
[src]
Returns a queue.
pub fn as_receiver(&self) -> &R
[src]
Returns a reference to the receiver
.
pub fn as_mut_receiver(&mut self) -> &mut R
[src]
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<'_, R> AsRef<R> for Checkpoint<'_, Record<R>, R>
[src]
impl<'_, R> AsRef<R> for Checkpoint<'_, History<R>, R>
[src]
impl<'_, R> AsMut<R> for Checkpoint<'_, Record<R>, R>
[src]
impl<'_, R> AsMut<R> for Checkpoint<'_, History<R>, R>
[src]
impl<'a, T, R> From<&'a mut T> for Checkpoint<'a, T, R>
[src]
impl<'a, T: Debug, R: Debug> Debug for Checkpoint<'a, T, R>
[src]
Auto Trait Implementations
impl<'a, T, R> !Sync for Checkpoint<'a, T, R>
impl<'a, T, R> !Send for Checkpoint<'a, T, R>
impl<'a, T, R> Unpin for Checkpoint<'a, T, R>
impl<'a, T, R> !UnwindSafe for Checkpoint<'a, T, R>
impl<'a, T, R> !RefUnwindSafe for Checkpoint<'a, T, R>
Blanket Implementations
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,