Skip to main content

History

Struct History 

Source
pub struct History { /* private fields */ }
Expand description

A bounded undo and redo history. See the module docs.

Implementations§

Source§

impl History

Source

pub fn new(limit: usize) -> Self

A history keeping at most limit undo entries; 0 disables it.

Source

pub fn limit(&self) -> usize

The most undo entries kept.

Source

pub fn set_limit(&mut self, limit: usize)

Change the bound, dropping the oldest undo entries and the farthest redo entries beyond it.

Source

pub fn undo_len(&self) -> usize

Entries History::undo can step back through.

Source

pub fn redo_len(&self) -> usize

Entries History::redo can step forward through.

Source

pub fn can_undo(&self) -> bool

Whether History::undo has an entry.

Source

pub fn can_redo(&self) -> bool

Whether History::redo has an entry.

Source

pub fn clear(&mut self)

Drop every entry.

Source

pub fn push(&mut self, inverse: Inverse)

Keep inverse as the newest undo entry and clear redo.

Ignored when the history is disabled or the inverse is empty. If the inverse began at a revision the history does not describe, the old entries are dropped first.

Source

pub fn track<T>( &mut self, model: &mut Model, change: impl FnOnce(&mut Model) -> T, ) -> T

Run change on model and keep the inverse of what it wrote as one entry.

Whatever change wrote is kept whether it returned Ok or Err; nothing is rolled back. With a limit of 0 the change runs unrecorded.

Source

pub fn peek_undo(&self, model: &Model) -> Result<Restored, HistoryError>

What History::undo would change, without changing it.

Source

pub fn peek_redo(&self, model: &Model) -> Result<Restored, HistoryError>

What History::redo would change, without changing it.

Source

pub fn undo(&mut self, model: &mut Model) -> Result<Restored, HistoryError>

Undo the newest entry.

Source

pub fn rollback(&mut self, model: &mut Model) -> Result<Restored, HistoryError>

Undo the newest entry and forget it: the model changes exactly as History::undo changes it, with the same revision check and the same refusals (the history is unchanged on a refusal), but the entry is dropped instead of moved to the redo stack.

For a change that is abandoned, not undone by the user. Redo is cleared, as History::push clears it: the model moved to a state the redo entries were not recorded against, so redoing them would replay onto the wrong base. In the usual case (the newest entry just tracked) redo was empty already and stays empty.

Source

pub fn redo(&mut self, model: &mut Model) -> Result<Restored, HistoryError>

Redo the most recently undone entry.

Trait Implementations§

Source§

impl Clone for History

Source§

fn clone(&self) -> History

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for History

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for History

Source§

fn default() -> History

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.