Struct undo::timeline::Timeline[][src]

pub struct Timeline<C, const LIMIT: usize> { /* fields omitted */ }

A timeline of commands.

A timeline works mostly like a record but stores a fixed number of commands on the stack.

Can be used without the alloc feature.

Examples

let mut target = String::new();
let mut timeline = Timeline::<_, 32>::new();
timeline.apply(&mut target, Add('a'))?;
timeline.apply(&mut target, Add('b'))?;
timeline.apply(&mut target, Add('c'))?;
assert_eq!(target, "abc");
timeline.undo(&mut target)?;
timeline.undo(&mut target)?;
timeline.undo(&mut target)?;
assert_eq!(target, "");
timeline.redo(&mut target)?;
timeline.redo(&mut target)?;
timeline.redo(&mut target)?;
assert_eq!(target, "abc");

Implementations

impl<C, const LIMIT: usize> Timeline<C, LIMIT>[src]

pub fn new() -> Timeline<C, LIMIT>[src]

Returns a new timeline.

impl<C, const LIMIT: usize> Timeline<C, LIMIT>[src]

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

Returns the number of commands in the timeline.

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

Returns true if the timeline is empty.

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

Returns true if the timeline can undo.

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

Returns true if the timeline 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 display(&self) -> Display<'_, C, LIMIT>[src]

Returns a structure for configurable formatting of the record.

impl<C: Command, const LIMIT: usize> Timeline<C, LIMIT>[src]

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

Pushes the command on top of the timeline 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.

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 timeline without undoing them.

impl<C: ToString, const LIMIT: usize> Timeline<C, LIMIT>[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, const LIMIT: usize> Clone for Timeline<C, LIMIT>[src]

impl<C: Debug, const LIMIT: usize> Debug for Timeline<C, LIMIT>[src]

impl<C, const LIMIT: usize> Default for Timeline<C, LIMIT>[src]

impl<'de, C, const LIMIT: usize> Deserialize<'de> for Timeline<C, LIMIT> where
    C: Deserialize<'de>, 
[src]

impl<'a, C, const LIMIT: usize> From<&'a Timeline<C, LIMIT>> for Display<'a, C, LIMIT>[src]

impl<C, const LIMIT: usize> Serialize for Timeline<C, LIMIT> where
    C: Serialize
[src]

Auto Trait Implementations

impl<C, const LIMIT: usize> RefUnwindSafe for Timeline<C, LIMIT> where
    C: RefUnwindSafe

impl<C, const LIMIT: usize> Send for Timeline<C, LIMIT> where
    C: Send

impl<C, const LIMIT: usize> Sync for Timeline<C, LIMIT> where
    C: Sync

impl<C, const LIMIT: usize> Unpin for Timeline<C, LIMIT> where
    C: Unpin

impl<C, const LIMIT: usize> UnwindSafe for Timeline<C, LIMIT> where
    C: 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> 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.