[−][src]Struct undo::Record
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 record = Record::default(); record.apply(Add('a'))?; record.apply(Add('b'))?; record.apply(Add('c'))?; assert_eq!(record.target(), "abc"); record.undo()?; record.undo()?; record.undo()?; assert_eq!(record.target(), ""); record.redo()?; record.redo()?; record.redo()?; assert_eq!(record.target(), "abc");
Implementations
impl<T> Record<T>
[src]
pub fn new(target: T) -> Record<T>
[src]
Returns a new record.
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: impl FnMut(Signal) + 'static
) -> Option<impl FnMut(Signal) + 'static>
[src]
&mut self,
slot: impl FnMut(Signal) + 'static
) -> Option<impl FnMut(Signal) + 'static>
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<impl FnMut(Signal) + 'static>
[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 set_saved(&mut self, saved: bool)
[src]
Marks the target as currently being in a saved or unsaved state.
pub fn revert(&mut self) -> Option<Result>
[src]
Revert the changes done to the target since the saved state.
pub fn current(&self) -> usize
[src]
Returns the position of the current command.
pub fn clear(&mut self)
[src]
Removes all commands from the record without undoing them.
pub fn apply(&mut self, command: impl Command<T>) -> Result
[src]
Pushes the command to the 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) -> Result
[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
[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, current: usize) -> Option<Result>
[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, to: &DateTime<impl TimeZone>) -> Option<Result>
[src]
Go back or forward in the record to the command that was made closest to the datetime provided.
pub fn queue(&mut self) -> Queue<'_, T>
[src]
Returns a queue.
pub fn checkpoint(&mut self) -> Checkpoint<'_, T>
[src]
Returns a checkpoint.
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
.
pub fn display(&self) -> Display<'_, T>
[src]
Returns a structure for configurable formatting of the record.
Requires the display
feature to be enabled.
pub fn target(&self) -> &T
[src]
Returns a reference to the target
.
pub fn target_mut(&mut self) -> &mut T
[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) -> T
[src]
Consumes the record, returning the target
.
Trait Implementations
impl<T: Debug + 'static> Debug for Record<T>
[src]
impl<T: Default> Default for Record<T>
[src]
impl<'a, T> From<&'a Record<T>> for Display<'a, T>
[src]
impl<'a, T> From<&'a mut Record<T>> for Checkpoint<'a, T>
[src]
impl<'a, T> From<&'a mut Record<T>> for Queue<'a, T>
[src]
impl<T> From<T> for Record<T>
[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Record<T>
impl<T> !Send for Record<T>
impl<T> !Sync for Record<T>
impl<T> Unpin for Record<T> where
T: Unpin,
T: Unpin,
impl<T> !UnwindSafe for Record<T>
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,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<!> for T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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.
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>,