Struct undo::history::History [−][src]
A history of actions.
Unlike Record which maintains a linear undo history, History maintains an undo tree containing every edit made to the target.
Examples
let mut target = String::new(); let mut history = History::new(); history.apply(&mut target, Add('a'))?; history.apply(&mut target, Add('b'))?; history.apply(&mut target, Add('c'))?; let abc = history.branch(); history.go_to(&mut target, abc, 1).unwrap()?; history.apply(&mut target, Add('f'))?; history.apply(&mut target, Add('g'))?; assert_eq!(target, "afg"); history.go_to(&mut target, abc, 3).unwrap()?; assert_eq!(target, "abc");
Implementations
impl<A> History<A>
[src]
impl<A, F> History<A, F>
[src]
pub fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional
more actions.
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 actions 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 action.
pub fn queue(&mut self) -> Queue<'_, A, F>
[src]
Returns a queue.
pub fn checkpoint(&mut self) -> Checkpoint<'_, A, F>
[src]
Returns a checkpoint.
pub fn display(&self) -> Display<'_, A, F>
[src]
Returns a structure for configurable formatting of the history.
impl<A: Action, F: FnMut(Signal)> History<A, F>
[src]
pub fn apply(&mut self, target: &mut A::Target, action: A) -> Result<A>
[src]
Pushes the action 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, target: &mut A::Target) -> Result<A>
[src]
Calls the undo
method for the active action
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 A::Target) -> Result<A>
[src]
Calls the redo
method for the active action
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,
target: &mut A::Target,
branch: usize,
current: usize
) -> Option<Result<A>>
[src]
&mut self,
target: &mut A::Target,
branch: usize,
current: usize
) -> Option<Result<A>>
Repeatedly calls undo
or redo
until the action 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,
target: &mut A::Target,
to: &DateTime<impl TimeZone>
) -> Option<Result<A>>
[src]
&mut self,
target: &mut A::Target,
to: &DateTime<impl TimeZone>
) -> Option<Result<A>>
Go back or forward in the history to the action that was made closest to the datetime provided.
This method does not jump across branches.
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 actions from the history without undoing them.
impl<A: ToString, F> History<A, F>
[src]
pub fn undo_text(&self) -> Option<String>
[src]
Returns the string of the action which will be undone
in the next call to undo
.
pub fn redo_text(&self) -> Option<String>
[src]
Returns the string of the action which will be redone
in the next call to redo
.
Trait Implementations
impl<A: Clone, F: Clone> Clone for History<A, F>
[src]
impl<A: Debug, F> Debug for History<A, F>
[src]
impl<A> Default for History<A>
[src]
impl<'de, A, F> Deserialize<'de> for History<A, F> where
A: Deserialize<'de>,
[src]
A: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<'a, A, F> From<&'a History<A, F>> for Display<'a, A, F>
[src]
impl<'a, A, F> From<&'a mut History<A, F>> for Queue<'a, A, F>
[src]
impl<'a, A, F> From<&'a mut History<A, F>> for Checkpoint<'a, A, F>
[src]
impl<A, F> From<History<A, F>> for Record<A, F>
[src]
impl<A, F> From<Record<A, F>> for History<A, F>
[src]
impl<A, F> Serialize for History<A, F> where
A: Serialize,
[src]
A: Serialize,
Auto Trait Implementations
impl<A, F> RefUnwindSafe for History<A, F> where
A: RefUnwindSafe,
F: RefUnwindSafe,
A: RefUnwindSafe,
F: RefUnwindSafe,
impl<A, F> Send for History<A, F> where
A: Send,
F: Send,
A: Send,
F: Send,
impl<A, F> Sync for History<A, F> where
A: Sync,
F: Sync,
A: Sync,
F: Sync,
impl<A, F> Unpin for History<A, F> where
A: Unpin,
F: Unpin,
A: Unpin,
F: Unpin,
impl<A, F> UnwindSafe for History<A, F> where
A: RefUnwindSafe + UnwindSafe,
F: UnwindSafe,
A: RefUnwindSafe + UnwindSafe,
F: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut 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.
pub 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>,