[][src]Struct redo::history::History

pub struct History<C: Command, F = fn(_: Signal)> { /* fields omitted */ }

A history of commands.

Unlike Record which maintains a linear undo history, History maintains an undo tree containing every edit made to the target.

Examples

let mut history = History::default();
history.apply(Add('a'))?;
history.apply(Add('b'))?;
history.apply(Add('c'))?;
let abc = history.branch();
history.go_to(abc, 1).unwrap()?;
history.apply(Add('f'))?;
history.apply(Add('g'))?;
assert_eq!(history.target(), "afg");
history.go_to(abc, 3).unwrap()?;
assert_eq!(history.target(), "abc");

Implementations

impl<C: Command> History<C>[src]

pub fn new(target: C::Target) -> History<C>[src]

Returns a new history.

impl<C: Command, F> History<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 history.

pub fn shrink_to_fit(&mut self)[src]

Shrinks the capacity of the history as much as possible.

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

Returns the number of commands in the current branch of the history.

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

Returns true if the current branch of the history is empty.

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

Returns the limit of the history.

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 is_saved(&self) -> bool[src]

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

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

Returns true if the history can undo.

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

Returns true if the history can redo.

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

Returns the current branch.

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

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

Returns a reference to the target.

pub fn target_mut(&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.

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

Consumes the history, returning the target.

impl<C: Command, F: FnMut(Signal)> History<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 clear(&mut self)[src]

Removes all commands from the history without undoing them.

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

Pushes the command to the top of the history and executes its apply method.

Errors

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

pub fn undo(&mut self) -> 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) -> 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 executing redo the error is returned.

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

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

Errors

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

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

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

This method does not jump across branches.

impl<C: Command + ToString, F> History<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: Command, F> Debug for History<C, F> where
    C: Debug,
    C::Target: Debug
[src]

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

impl<'de, C: Command, F> Deserialize<'de> for History<C, F> where
    C: Command + Deserialize<'de>,
    C::Target: Deserialize<'de>, 
[src]

impl<'a, C: Command, F> From<&'a History<C, F>> for Display<'a, C, F>[src]

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

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

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

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

impl<C: Command, F> Serialize for History<C, F> where
    C: Command + Serialize,
    C::Target: Serialize
[src]

Auto Trait Implementations

impl<C, F> RefUnwindSafe for History<C, F> where
    C: RefUnwindSafe,
    F: RefUnwindSafe,
    <C as Command>::Target: RefUnwindSafe

impl<C, F> Send for History<C, F> where
    C: Send,
    F: Send,
    <C as Command>::Target: Send

impl<C, F> Sync for History<C, F> where
    C: Sync,
    F: Sync,
    <C as Command>::Target: Sync

impl<C, F> Unpin for History<C, F> where
    C: Unpin,
    F: Unpin,
    <C as Command>::Target: Unpin

impl<C, F> UnwindSafe for History<C, F> where
    C: RefUnwindSafe + UnwindSafe,
    F: UnwindSafe,
    <C as Command>::Target: UnwindSafe

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