[][src]Struct redo::Checkpoint

pub struct Checkpoint<'a, T, C> { /* fields omitted */ }

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_target(), "abc");
cp.cancel()?;
assert_eq!(record.as_target(), "");

Methods

impl<'a, T, C> Checkpoint<'a, T, C>[src]

pub fn new(inner: &'a mut T) -> Checkpoint<'a, T, C>[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<'_, C: Command, F: FnMut(Signal)> Checkpoint<'_, Record<C, F>, C>[src]

pub fn apply(&mut self, command: C) -> Result<C>[src]

Calls the apply method.

pub fn undo(&mut self) -> Option<Result<C>>[src]

Calls the undo method.

pub fn redo(&mut self) -> Option<Result<C>>[src]

Calls the redo method.

pub fn go_to(&mut self, current: usize) -> Option<Result<C>>[src]

Calls the go_to method.

pub fn extend(&mut self, commands: impl IntoIterator<Item = C>) -> Result<C>[src]

Calls the extend method.

pub fn cancel(self) -> Result<C>[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<C, F>, C>[src]

Returns a checkpoint.

pub fn queue(&mut self) -> Queue<Record<C, F>, C>[src]

Returns a queue.

pub fn as_target(&self) -> &C::Target[src]

Returns a reference to the target.

pub fn as_mut_target(&mut self) -> &mut C::Target[src]

Returns a mutable reference to the target.

This method should only be used when doing changes that should not be able to be undone.

impl<'_, C: Command, F: FnMut(Signal)> Checkpoint<'_, History<C, F>, C>[src]

pub fn apply(&mut self, command: C) -> Result<C>[src]

Calls the apply method.

pub fn undo(&mut self) -> Option<Result<C>>[src]

Calls the undo method.

pub fn redo(&mut self) -> Option<Result<C>>[src]

Calls the redo method.

pub fn go_to(&mut self, branch: usize, current: usize) -> Option<Result<C>>[src]

Calls the go_to method.

pub fn extend(&mut self, commands: impl IntoIterator<Item = C>) -> Result<C>[src]

Calls the extend method.

pub fn cancel(self) -> Result<C>[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<History<C, F>, C>[src]

Returns a checkpoint.

pub fn queue(&mut self) -> Queue<History<C, F>, C>[src]

Returns a queue.

pub fn as_target(&self) -> &C::Target[src]

Returns a reference to the target.

pub fn as_mut_target(&mut self) -> &mut C::Target[src]

Returns a mutable reference to the target.

This method should only be used when doing changes that should not be able to be undone.

Trait Implementations

impl<'a, T, C> From<&'a mut T> for Checkpoint<'a, T, C>[src]

impl<'a, T: Debug, C: Debug> Debug for Checkpoint<'a, T, C>[src]

impl<'a, T: PartialEq, C: PartialEq> PartialEq<Checkpoint<'a, T, C>> for Checkpoint<'a, T, C>[src]

impl<'a, T: Eq, C: Eq> Eq for Checkpoint<'a, T, C>[src]

impl<'a, T: Ord, C: Ord> Ord for Checkpoint<'a, T, C>[src]

impl<'a, T: PartialOrd, C: PartialOrd> PartialOrd<Checkpoint<'a, T, C>> for Checkpoint<'a, T, C>[src]

impl<'a, T: Hash, C: Hash> Hash for Checkpoint<'a, T, C>[src]

impl<'a, T, C> StructuralPartialEq for Checkpoint<'a, T, C>[src]

impl<'a, T, C> StructuralEq for Checkpoint<'a, T, C>[src]

impl<'_, C: Command, F> AsRef<<C as Command>::Target> for Checkpoint<'_, Record<C, F>, C>[src]

impl<'_, C: Command, F> AsRef<<C as Command>::Target> for Checkpoint<'_, History<C, F>, C>[src]

impl<'_, C: Command, F> AsMut<<C as Command>::Target> for Checkpoint<'_, Record<C, F>, C>[src]

impl<'_, C: Command, F> AsMut<<C as Command>::Target> for Checkpoint<'_, History<C, F>, C>[src]

Auto Trait Implementations

impl<'a, T, C> Unpin for Checkpoint<'a, T, C> where
    C: Unpin

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> !UnwindSafe for Checkpoint<'a, T, C>

impl<'a, T, C> RefUnwindSafe for Checkpoint<'a, T, C> where
    C: RefUnwindSafe,
    T: RefUnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]