[−][src]Struct redo::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.as_target(), "abc"); record.undo().unwrap()?; record.undo().unwrap()?; record.undo().unwrap()?; assert_eq!(record.as_target(), ""); record.redo().unwrap()?; record.redo().unwrap()?; record.redo().unwrap()?; assert_eq!(record.as_target(), "abc");
Methods
impl<C: Command> Record<C>
[src]
pub fn new(target: C::Target) -> Record<C>
[src]
Returns a new record.
pub fn builder() -> RecordBuilder<C>
[src]
Returns a builder for a record.
impl<C: Command, 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 current(&self) -> usize
[src]
Returns the position of the current command.
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 connect_with<G>(self, slot: G) -> Record<C, G>
[src]
Creates a new record that uses the provided slot.
pub fn disconnect(&mut self) -> Option<F>
[src]
Removes and returns the slot.
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 record can undo.
pub fn can_redo(&self) -> bool
[src]
Returns true
if the record can redo.
pub fn checkpoint(&mut self) -> Checkpoint<Record<C, F>, C>
[src]
Returns a checkpoint.
pub fn queue(&mut self) -> Queue<Record<C, F>, C>
[src]
Returns a queue.
pub fn as_target(&self) -> &C::Target
[src]
Returns a reference to the target
.
pub fn as_mut_target(&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 record, returning the target
.
impl<C: Command, F: FnMut(Signal)> Record<C, F>
[src]
pub fn set_limit(&mut self, limit: usize) -> usize
[src]
Sets the limit of the record and returns the new limit.
If this limit is reached it will start popping of commands at the beginning of the record when new commands are applied. No limit is set by default which means it may grow indefinitely.
If 0 < limit < len
the first commands will be removed until len == limit
.
However, if the current active command is going to be removed, the limit is instead
adjusted to len - active
so the active command is not removed.
Panics
Panics if limit
is 0
.
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<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, 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) -> Option<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) -> Option<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, 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, 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 extend(&mut self, commands: impl IntoIterator<Item = C>) -> Result<C>
[src]
impl<C: Command + ToString, F> Record<C, F>
[src]
pub fn to_undo_string(&self) -> Option<String>
[src]
Returns the string of the command which will be undone in the next call to undo
.
pub fn to_redo_string(&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<Self>
[src]
Returns a structure for configurable formatting of the record.
Requires the display
feature to be enabled.
Trait Implementations
impl<C: Command, F> From<Record<C, F>> for History<C, F>
[src]
impl<C: Command, F> From<History<C, F>> for Record<C, F>
[src]
impl<C: Command, F> Display for Record<C, F> where
C: Display,
C::Target: Display,
[src]
C: Display,
C::Target: Display,
impl<C: Command, F> Debug for Record<C, F> where
C: Debug,
C::Target: Debug,
[src]
C: Debug,
C::Target: Debug,
impl<C: Command, F> AsRef<<C as Command>::Target> for Record<C, F>
[src]
impl<C: Command, F> AsMut<<C as Command>::Target> for Record<C, F>
[src]
impl<C: Command> Default for Record<C> where
C::Target: Default,
[src]
C::Target: Default,
impl<C: Command, F> Serialize for Record<C, F> where
C: Serialize,
C::Target: Serialize,
[src]
C: Serialize,
C::Target: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de, C: Command, F> Deserialize<'de> for Record<C, F> where
C: Deserialize<'de>,
C::Target: Deserialize<'de>,
[src]
C: Deserialize<'de>,
C::Target: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
impl<C, F> Unpin for Record<C, F> where
C: Unpin,
F: Unpin,
<C as Command>::Target: Unpin,
C: Unpin,
F: Unpin,
<C as Command>::Target: Unpin,
impl<C, F> Send for Record<C, F> where
C: Send,
F: Send,
<C as Command>::Target: Send,
C: Send,
F: Send,
<C as Command>::Target: Send,
impl<C, F> Sync for Record<C, F> where
C: Sync,
F: Sync,
<C as Command>::Target: Sync,
C: Sync,
F: Sync,
<C as Command>::Target: Sync,
impl<C, F> UnwindSafe for Record<C, F> where
C: UnwindSafe,
F: UnwindSafe,
<C as Command>::Target: UnwindSafe,
C: UnwindSafe,
F: UnwindSafe,
<C as Command>::Target: UnwindSafe,
impl<C, F> RefUnwindSafe for Record<C, F> where
C: RefUnwindSafe,
F: RefUnwindSafe,
<C as Command>::Target: RefUnwindSafe,
C: RefUnwindSafe,
F: RefUnwindSafe,
<C as Command>::Target: RefUnwindSafe,
Blanket Implementations
impl<T> From<T> for 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.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,