Skip to main content

NSUndoManager

Struct NSUndoManager 

Source
pub struct NSUndoManager<T> { /* private fields */ }
Expand description

Bounded ringbuffer undo/redo state manager (NSUndoManager equivalent).

Implementations§

Source§

impl<T: Clone + PartialEq> NSUndoManager<T>

Source

pub fn new() -> Self

Creates a new NSUndoManager with default capacity (DEFAULT_UNDO_CAPACITY = 50).

Source

pub fn with_capacity(capacity: usize) -> Self

Creates a new NSUndoManager with a custom maximum capacity.

Source

pub fn capacity(&self) -> usize

Maximum snapshot capacity.

Source

pub fn undo_count(&self) -> usize

Number of recorded undo steps available.

Source

pub fn redo_count(&self) -> usize

Number of recorded redo steps available.

Source

pub fn can_undo(&self) -> bool

Returns true if an undo operation can be performed.

Source

pub fn can_redo(&self) -> bool

Returns true if a redo operation can be performed.

Source

pub fn is_grouping(&self) -> bool

Returns true if a coalesced undo group is currently open.

Source

pub fn peek_undo(&self) -> Option<&T>

Non-destructively inspects the most recent undo snapshot.

Source

pub fn peek_redo(&self) -> Option<&T>

Non-destructively inspects the most recent redo snapshot.

Source

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.

Source

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.

Source

pub fn push_snapshot(&mut self, state: T)

Records a new state snapshot on the undo stack.

In accordance with SPEC-008 §2.2:

  1. Ignores intermediate snapshots while a coalesced group (begin_grouping) is active.
  2. Deduplicates consecutive identical snapshots (no-op protection).
  3. Drops the oldest entry if the undo stack exceeds capacity.
  4. Unconditionally clears the redo stack.
Source

pub fn undo(&mut self, current_state: &mut T) -> bool

Performs an undo operation:

  • Pushes *current_state onto the redo stack.
  • Restores *current_state from the most recent undo snapshot.
  • Returns true if state was restored, or false if undo_stack was empty.
Source

pub fn redo(&mut self, current_state: &mut T) -> bool

Performs a redo operation:

  • Pushes *current_state onto the undo stack.
  • Restores *current_state from the most recent redo snapshot.
  • Returns true if state was restored, or false if redo_stack was empty.
Source

pub fn clear(&mut self)

Clears all undo and redo history.

Source

pub fn validate_invariants(&self) -> Result<(), String>

Validates all NSUndoManager structural invariants (GL-1015 §3.5):

  1. capacity >= 1
  2. undo_stack.len() <= capacity and redo_stack.len() <= capacity
  3. Zero consecutive identical snapshots in undo_stack

Trait Implementations§

Source§

impl<T: Clone> Clone for NSUndoManager<T>

Source§

fn clone(&self) -> Self

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<T: Debug> Debug for NSUndoManager<T>

Source§

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

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

impl<T: Clone + PartialEq> Default for NSUndoManager<T>

Source§

fn default() -> Self

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

impl<T: Eq> Eq for NSUndoManager<T>

Source§

impl<T: PartialEq> PartialEq for NSUndoManager<T>

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for NSUndoManager<T>

Auto Trait Implementations§

§

impl<T> Forget for NSUndoManager<T>

§

impl<T> Freeze for NSUndoManager<T>
where VecDeque<T>: Freeze, Option<T>: Freeze,

§

impl<T> RefUnwindSafe for NSUndoManager<T>

§

impl<T> Send for NSUndoManager<T>
where VecDeque<T>: Send, Option<T>: Send,

§

impl<T> Sync for NSUndoManager<T>
where VecDeque<T>: Sync, Option<T>: Sync,

§

impl<T> Unpin for NSUndoManager<T>
where VecDeque<T>: Unpin, Option<T>: Unpin,

§

impl<T> UnsafeUnpin for NSUndoManager<T>

§

impl<T> UnwindSafe for NSUndoManager<T>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

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

Checks if this value is equivalent to the given key. 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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

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

Source§

impl<T> SerializableAny for T
where T: 'static + Any + Clone + for<'a> Send + Sync,

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.