pub struct UndoStack<T> { /* private fields */ }Expand description
Generic bounded undo/redo stack over snapshots of type T.
record pushes the pre-mutation state onto the undo side and clears
any redo history (a fresh edit invalidates a previously-undone
future — standard editor semantics). undo/redo take the caller’s
current live state so they can push it onto the opposite side,
mirroring the classic two-stack undo/redo implementation.
Implementations§
Source§impl<T> UndoStack<T>
impl<T> UndoStack<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
An unbounded stack — history grows until Self::clear is called.
Sourcepub fn with_limit(limit: usize) -> Self
pub fn with_limit(limit: usize) -> Self
A stack that discards its oldest entry once limit is exceeded.
limit == 0 disables history: Self::record becomes a no-op
and Self::undo/Self::redo always return None.
Sourcepub fn record(&mut self, before: T)
pub fn record(&mut self, before: T)
Record before — the state immediately prior to a mutation the
caller is about to apply. Clears the redo side.
Sourcepub fn undo(&mut self, current: T) -> Option<T>
pub fn undo(&mut self, current: T) -> Option<T>
Undo one step. current is the caller’s live state — pushed onto
the redo side so a following Self::redo can restore it.
Returns the state to restore, or None if there’s nothing to
undo.
Sourcepub fn redo(&mut self, current: T) -> Option<T>
pub fn redo(&mut self, current: T) -> Option<T>
Redo one step, mirroring Self::undo: current is pushed back
onto the undo side.
Sourcepub fn can_undo(&self) -> bool
pub fn can_undo(&self) -> bool
Whether Self::undo would return Some.
Sourcepub fn can_redo(&self) -> bool
pub fn can_redo(&self) -> bool
Whether Self::redo would return Some.
Trait Implementations§
impl<T: Eq> Eq for UndoStack<T>
impl<T: PartialEq> StructuralPartialEq for UndoStack<T>
Auto Trait Implementations§
impl<T> Freeze for UndoStack<T>
impl<T> RefUnwindSafe for UndoStack<T>
impl<T> Send for UndoStack<T>
impl<T> Sync for UndoStack<T>
impl<T> Unpin for UndoStack<T>
impl<T> UnsafeUnpin for UndoStack<T>
impl<T> UnwindSafe for UndoStack<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more