pub struct History { /* private fields */ }Expand description
Undo/redo stacks of Patches for one mesh, limited by a memory budget.
Every commit on the mesh must be pushed here (or the history cleared): undo and
redo only work when the mesh revision matches the top patch. A history belongs to
the mesh of its first pushed patch; every method that takes a mesh rejects any
other mesh with StoreError::PatchMismatch.
The history also decides when removed slots may be reused. A slot freed by a
patch stays reserved while that patch can still be undone, and a slot created by
an undone patch stays reserved while it can be redone. Evicting or discarding the
patch releases the slot. Patches kept outside a History release their slots
through Mesh::release_patch_slots, at most once and only once no history
still holds the patch; slots never released that way are reclaimed by
Mesh::compact. Patches made stale by a direct Mesh::compact release
nothing: their slots no longer exist.
The budget counts undo and redo patches together, but eviction only drops undo
patches (oldest first). While a large redo stack exists, History::bytes may
therefore exceed History::budget; the redo stack is dropped by the next push.
Implementations§
Source§impl History
impl History
Sourcepub fn new(budget_bytes: usize) -> Self
pub fn new(budget_bytes: usize) -> Self
A history that keeps at most budget_bytes of patches (undo and redo combined).
Sourcepub fn push(&mut self, mesh: &mut Mesh, patch: Patch) -> Result<()>
pub fn push(&mut self, mesh: &mut Mesh, patch: Patch) -> Result<()>
Records a just-committed patch. Empty patches are ignored and keep the redo stack. Otherwise the redo stack is discarded and the oldest patches are evicted until the budget is met (possibly including this one, if it alone is too large).
Sourcepub fn undo(&mut self, mesh: &mut Mesh) -> Result<Option<ChangeSet>>
pub fn undo(&mut self, mesh: &mut Mesh) -> Result<Option<ChangeSet>>
Undoes the latest patch. Returns None when there is nothing to undo.
Sourcepub fn redo(&mut self, mesh: &mut Mesh) -> Result<Option<ChangeSet>>
pub fn redo(&mut self, mesh: &mut Mesh) -> Result<Option<ChangeSet>>
Redoes the latest undone patch. Returns None when there is nothing to redo.
Sourcepub fn clear(&mut self, mesh: &mut Mesh) -> Result<()>
pub fn clear(&mut self, mesh: &mut Mesh) -> Result<()>
Drops all patches and releases the slots they reserved.
Sourcepub fn compact(&mut self, mesh: &mut Mesh) -> Result<Remap>
pub fn compact(&mut self, mesh: &mut Mesh) -> Result<Remap>
Clears the history and compacts the mesh (see Mesh::compact).
Sourcepub fn set_budget(&mut self, mesh: &mut Mesh, budget_bytes: usize) -> Result<()>
pub fn set_budget(&mut self, mesh: &mut Mesh, budget_bytes: usize) -> Result<()>
Changes the budget, evicting old undo patches if needed.
pub fn can_undo(&self) -> bool
pub fn can_redo(&self) -> bool
pub fn undo_len(&self) -> usize
pub fn redo_len(&self) -> usize
Sourcepub fn bytes(&self) -> usize
pub fn bytes(&self) -> usize
Memory held by all patches (undo and redo), in bytes. Can exceed the budget while a redo stack exists; see the type docs.