Skip to main content

History

Struct History 

Source
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

Source

pub fn new(budget_bytes: usize) -> Self

A history that keeps at most budget_bytes of patches (undo and redo combined).

Source

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).

Source

pub fn undo(&mut self, mesh: &mut Mesh) -> Result<Option<ChangeSet>>

Undoes the latest patch. Returns None when there is nothing to undo.

Source

pub fn redo(&mut self, mesh: &mut Mesh) -> Result<Option<ChangeSet>>

Redoes the latest undone patch. Returns None when there is nothing to redo.

Source

pub fn clear(&mut self, mesh: &mut Mesh) -> Result<()>

Drops all patches and releases the slots they reserved.

Source

pub fn compact(&mut self, mesh: &mut Mesh) -> Result<Remap>

Clears the history and compacts the mesh (see Mesh::compact).

Source

pub fn set_budget(&mut self, mesh: &mut Mesh, budget_bytes: usize) -> Result<()>

Changes the budget, evicting old undo patches if needed.

Source

pub fn can_undo(&self) -> bool

Source

pub fn can_redo(&self) -> bool

Source

pub fn undo_len(&self) -> usize

Source

pub fn redo_len(&self) -> usize

Source

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.

Source

pub fn budget(&self) -> usize

Auto Trait Implementations§

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<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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.