ass_editor/core/history/stack.rs
1//! Undo/redo stack storage.
2//!
3//! [`UndoStack`] owns the undo and redo queues plus the optional arena used for
4//! temporary allocations; its inherent methods live in the sibling `stack_impl`
5//! module, so the fields are `pub(super)` for use across the `history` subtree.
6
7use super::{HistoryEntry, UndoStackConfig};
8
9#[cfg(feature = "arena")]
10use bumpalo::Bump;
11
12#[cfg(feature = "std")]
13use std::collections::VecDeque;
14
15#[cfg(not(feature = "std"))]
16use alloc::collections::VecDeque;
17
18/// Undo/redo stack with efficient memory management
19///
20/// Uses a circular buffer design with arena allocation for optimal
21/// performance. Supports configurable limits and automatic cleanup.
22#[derive(Debug)]
23pub struct UndoStack {
24 /// Configuration for this stack
25 pub(super) config: UndoStackConfig,
26
27 /// Undo history (most recent operations first)
28 pub(super) undo_stack: VecDeque<HistoryEntry>,
29
30 /// Redo history (operations that can be redone)
31 pub(super) redo_stack: VecDeque<HistoryEntry>,
32
33 /// Current memory usage in bytes
34 pub(super) current_memory: usize,
35
36 /// Arena for temporary allocations
37 #[cfg(feature = "arena")]
38 pub(super) arena: Bump,
39
40 /// Number of operations since last arena reset
41 #[cfg(feature = "arena")]
42 pub(super) ops_since_reset: usize,
43}
44
45impl Default for UndoStack {
46 fn default() -> Self {
47 Self::new()
48 }
49}