[][src]Struct undo::record::Record

pub struct Record<C, F = Box<dyn FnMut(Signal)>> { /* fields omitted */ }

A record of commands.

The record can roll the targets state backwards and forwards by using the undo and redo methods. In addition, the record can notify the user about changes to the stack or the target through signal. The user can give the record a function that is called each time the state changes by using the builder.

Examples

let mut target = String::new();
let mut record = Record::new();
record.apply(&mut target, Add('a'))?;
record.apply(&mut target, Add('b'))?;
record.apply(&mut target, Add('c'))?;
assert_eq!(target, "abc");
record.undo(&mut target)?;
record.undo(&mut target)?;
record.undo(&mut target)?;
assert_eq!(target, "");
record.redo(&mut target)?;
record.redo(&mut target)?;
record.redo(&mut target)?;
assert_eq!(target, "abc");

Implementations

impl<C> Record<C>[src]

pub fn new() -> Record<C>[src]

Returns a new record.

impl<C, F> Record<C, F>[src]

pub fn reserve(&mut self, additional: usize)[src]

Reserves capacity for at least additional more commands.

Panics

Panics if the new capacity overflows usize.

pub fn capacity(&self) -> usize[src]

Returns the capacity of the record.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the record as much as possible.

pub fn len(&self) -> usize[src]

Returns the number of commands in the record.

pub fn is_empty(&self) -> bool[src]

Returns true if the record is empty.

pub fn limit(&self) -> usize[src]

Returns the limit of the record.

pub fn connect(&mut self, slot: F) -> Option<F>[src]

Sets how the signal should be handled when the state changes.

The previous slot is returned if it exists.

pub fn disconnect(&mut self) -> Option<F>[src]

Removes and returns the slot if it exists.

pub fn can_undo(&self) -> bool[src]

Returns true if the record can undo.

pub fn can_redo(&self) -> bool[src]

Returns true if the record can redo.

pub fn is_saved(&self) -> bool[src]

Returns true if the target is in a saved state, false otherwise.

pub fn current(&self) -> usize[src]

Returns the position of the current command.

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

Returns a queue.

pub fn checkpoint(&mut self) -> Checkpoint<'_, C, F>[src]

Returns a checkpoint.

pub fn display(&self) -> Display<'_, C, F>[src]

Returns a structure for configurable formatting of the record.

impl<C: Command, F: FnMut(Signal)> Record<C, F>[src]

pub fn set_saved(&mut self, saved: bool)[src]

Marks the target as currently being in a saved or unsaved state.

pub fn revert(&mut self, target: &mut C::Target) -> Option<Result<C>>[src]

Revert the changes done to the target since the saved state.

pub fn clear(&mut self)[src]

Removes all commands from the record without undoing them.

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

Pushes the command on top of the record and executes its apply method.

Errors

If an error occur when executing apply the error is returned.

pub fn undo(&mut self, target: &mut C::Target) -> Result<C>[src]

Calls the undo method for the active command and sets the previous one as the new active one.

Errors

If an error occur when executing undo the error is returned.

pub fn redo(&mut self, target: &mut C::Target) -> Result<C>[src]

Calls the redo method for the active command and sets the next one as the new active one.

Errors

If an error occur when applying redo the error is returned.

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

Repeatedly calls undo or redo until the command at current is reached.

Errors

If an error occur when executing undo or redo the error is returned.

pub fn time_travel(
    &mut self,
    target: &mut C::Target,
    to: &DateTime<impl TimeZone>
) -> Option<Result<C>>
[src]

Go back or forward in the record to the command that was made closest to the datetime provided.

impl<C: ToString, F> Record<C, F>[src]

pub fn undo_text(&self) -> Option<String>[src]

Returns the string of the command which will be undone in the next call to undo.

pub fn redo_text(&self) -> Option<String>[src]

Returns the string of the command which will be redone in the next call to redo.

Trait Implementations

impl<C: Clone, F: Clone> Clone for Record<C, F>[src]

impl<C, F> Debug for Record<C, F> where
    C: Debug
[src]

impl<C: Command> Default for Record<C> where
    C::Target: Default
[src]

impl<'de, C, F> Deserialize<'de> for Record<C, F> where
    C: Deserialize<'de>, 
[src]

impl<'a, C, F> From<&'a Record<C, F>> for Display<'a, C, F>[src]

impl<'a, C, F> From<&'a mut Record<C, F>> for Queue<'a, C, F>[src]

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

impl<C, F> From<History<C, F>> for Record<C, F>[src]

impl<C, F> From<Record<C, F>> for History<C, F>[src]

impl<C, F> Serialize for Record<C, F> where
    C: Serialize
[src]

Auto Trait Implementations

impl<C, F> RefUnwindSafe for Record<C, F> where
    C: RefUnwindSafe,
    F: RefUnwindSafe
[src]

impl<C, F> Send for Record<C, F> where
    C: Send,
    F: Send
[src]

impl<C, F> Sync for Record<C, F> where
    C: Sync,
    F: Sync
[src]

impl<C, F> Unpin for Record<C, F> where
    C: Unpin,
    F: Unpin
[src]

impl<C, F> UnwindSafe for Record<C, F> where
    C: UnwindSafe,
    F: UnwindSafe
[src]

Blanket Implementations

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

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

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

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

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

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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> 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.