Struct biodivine_sketchbook::app::state::_undo_stack::UndoStack

source ·
pub struct UndoStack {
    event_limit: usize,
    payload_limit: usize,
    current_payload_size: usize,
    undo_stack: VecDeque<UndoStackEntry>,
    redo_stack: VecDeque<UndoStackEntry>,
}
Expand description

The stack that keeps track of all the events that can be reversed.

It has a “normal” Rust API, but it also implements SessionState so that parts of it can be accessed as an app state object through events.

Fields§

§event_limit: usize

The number of events this UndoStack is allowed to track. Beyond this limit, the stack will start dropping the oldest events.

§payload_limit: usize

The number of bytes of payload that this UndoStack is allowed to store. Beyond this limit, the stack will start dropping the oldest events.

§current_payload_size: usize

The approximate size of all payloads stored on the undo_stack.

Note that the redo_stack does not count towards this value, because entries only move there from the undo_stack (i.e. after the payload size check) and when we push to the undo_stack, the redo_stack is erased. Hence, assuming all invariants hold, undo_stack + redo_stack < limit, even if we just track the undo_stack.

§undo_stack: VecDeque<UndoStackEntry>§redo_stack: VecDeque<UndoStackEntry>

Implementations§

source§

impl UndoStack

source

pub fn new(event_limit: usize, payload_limit: usize) -> UndoStack

source

pub fn can_undo(&self) -> bool

source

pub fn can_redo(&self) -> bool

source

pub fn clear(&mut self)

Remove all elements from the UndoStack.

source

pub fn undo_len(&self) -> usize

The number of events that can be un-done.

source

pub fn redo_len(&self) -> usize

The number of events that can be re-done.

source

pub fn do_action(&mut self, perform: UserAction, reverse: UserAction) -> bool

Notify the undo stack that a new action has been performed. This creates a new stack entry for this action. Furthermore, it erases any available “redo” actions.

Returns true if the events were successfully saved, or false if an error occurred, e.g. due to excessive payload size.

source

pub fn undo_action(&mut self) -> Option<UserAction>

Try to undo the current top of the undo stack. This action can be later re-done using Self::redo_action. Returns None if there is no action to undo, or the “reverse” UserAction originally supplied to Self::do_action.

source

pub fn redo_action(&mut self) -> Option<UserAction>

Try to redo the current top of the redo stack. This action can be later un-done using Self::undo_action. Returns None if there is no action to redo, or the “perform” UserAction originally supplied to Self::do_action.

source

fn drop_undo_event(&mut self) -> Option<UndoStackEntry>

Internal function to drop an UndoStackEntry from the undo_stack.

Trait Implementations§

source§

impl Clone for UndoStack

source§

fn clone(&self) -> UndoStack

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
source§

impl Default for UndoStack

source§

fn default() -> Self

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

impl PartialEq for UndoStack

source§

fn eq(&self, other: &UndoStack) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl SessionState for UndoStack

source§

fn perform_event( &mut self, _event: &Event, _at_path: &[&str], ) -> Result<Consumed, DynError>

Modify the session state using the provided event. The possible outcomes are described by Consumed.
source§

fn refresh( &self, full_path: &[String], at_path: &[&str], ) -> Result<Event, DynError>

“Read” session state into an event without modifying it.
source§

impl Eq for UndoStack

source§

impl StructuralPartialEq for UndoStack

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
source§

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

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

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T> Same for T

source§

type Output = T

Should always be Self
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.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T