pub struct NSUndoManager<T> { /* private fields */ }Expand description
Bounded ringbuffer undo/redo state manager (NSUndoManager equivalent).
Implementations§
Source§impl<T: Clone + PartialEq> NSUndoManager<T>
impl<T: Clone + PartialEq> NSUndoManager<T>
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new NSUndoManager with default capacity (DEFAULT_UNDO_CAPACITY = 50).
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new NSUndoManager with a custom maximum capacity.
Sourcepub fn undo_count(&self) -> usize
pub fn undo_count(&self) -> usize
Number of recorded undo steps available.
Sourcepub fn redo_count(&self) -> usize
pub fn redo_count(&self) -> usize
Number of recorded redo steps available.
Sourcepub fn is_grouping(&self) -> bool
pub fn is_grouping(&self) -> bool
Returns true if a coalesced undo group is currently open.
Sourcepub fn peek_undo(&self) -> Option<&T>
pub fn peek_undo(&self) -> Option<&T>
Non-destructively inspects the most recent undo snapshot.
Sourcepub fn peek_redo(&self) -> Option<&T>
pub fn peek_redo(&self) -> Option<&T>
Non-destructively inspects the most recent redo snapshot.
Sourcepub fn begin_grouping(&mut self, initial_state: T)
pub fn begin_grouping(&mut self, initial_state: T)
Begins a coalesced undo group (such as a continuous slider or canvas drag).
While a group is active, intermediate Self::push_snapshot calls are ignored
until Self::end_grouping commits the net state transition as a single undo step.
Sourcepub fn end_grouping(&mut self, final_state: &T) -> bool
pub fn end_grouping(&mut self, final_state: &T) -> bool
Ends the active coalesced undo group and records a single undo snapshot
if final_state differs from the group’s initial_state.
Sourcepub fn push_snapshot(&mut self, state: T)
pub fn push_snapshot(&mut self, state: T)
Records a new state snapshot on the undo stack.
In accordance with SPEC-008 §2.2:
- Ignores intermediate snapshots while a coalesced group (
begin_grouping) is active. - Deduplicates consecutive identical snapshots (
no-opprotection). - Drops the oldest entry if the undo stack exceeds capacity.
- Unconditionally clears the redo stack.
Sourcepub fn undo(&mut self, current_state: &mut T) -> bool
pub fn undo(&mut self, current_state: &mut T) -> bool
Performs an undo operation:
- Pushes
*current_stateonto the redo stack. - Restores
*current_statefrom the most recent undo snapshot. - Returns
trueif state was restored, orfalseifundo_stackwas empty.
Sourcepub fn redo(&mut self, current_state: &mut T) -> bool
pub fn redo(&mut self, current_state: &mut T) -> bool
Performs a redo operation:
- Pushes
*current_stateonto the undo stack. - Restores
*current_statefrom the most recent redo snapshot. - Returns
trueif state was restored, orfalseifredo_stackwas empty.
Sourcepub fn validate_invariants(&self) -> Result<(), String>
pub fn validate_invariants(&self) -> Result<(), String>
Validates all NSUndoManager structural invariants (GL-1015 §3.5):
capacity >= 1undo_stack.len() <= capacityandredo_stack.len() <= capacity- Zero consecutive identical snapshots in
undo_stack
Trait Implementations§
Source§impl<T: Clone> Clone for NSUndoManager<T>
impl<T: Clone> Clone for NSUndoManager<T>
Source§impl<T: Debug> Debug for NSUndoManager<T>
impl<T: Debug> Debug for NSUndoManager<T>
impl<T: Eq> Eq for NSUndoManager<T>
Source§impl<T: PartialEq> PartialEq for NSUndoManager<T>
impl<T: PartialEq> PartialEq for NSUndoManager<T>
impl<T: PartialEq> StructuralPartialEq for NSUndoManager<T>
Auto Trait Implementations§
impl<T> Forget for NSUndoManager<T>
impl<T> Freeze for NSUndoManager<T>
impl<T> RefUnwindSafe for NSUndoManager<T>
impl<T> Send for NSUndoManager<T>
impl<T> Sync for NSUndoManager<T>
impl<T> Unpin for NSUndoManager<T>
impl<T> UnsafeUnpin for NSUndoManager<T>
impl<T> UnwindSafe for NSUndoManager<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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
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