pub struct History {
current: EditProject,
undo: Vec<EditProject>,
redo: Vec<EditProject>,
limit: usize,
}Expand description
A bounded undo / redo stack wrapping a live EditProject.
Edits go through History::apply, which snapshots the project
before each change. Because apply runs the operation on a clone and
only commits when the project actually changed, apply then undo is
guaranteed to restore the exact prior state — no fragile per-operation
inverse derivation, and no-op operations never pollute the undo stack.
Fields§
§current: EditProject§undo: Vec<EditProject>§redo: Vec<EditProject>§limit: usizeImplementations§
Source§impl History
impl History
Sourcepub fn new(project: EditProject) -> Self
pub fn new(project: EditProject) -> Self
Wrap a project with an undo stack of the default depth.
Sourcepub fn with_limit(project: EditProject, limit: usize) -> Self
pub fn with_limit(project: EditProject, limit: usize) -> Self
Wrap a project with an undo stack of at most limit steps
(clamped to at least 1).
Sourcepub fn project(&self) -> &EditProject
pub fn project(&self) -> &EditProject
The live project.
Sourcepub fn apply(&mut self, op: &EditOp) -> Result<(), EditError>
pub fn apply(&mut self, op: &EditOp) -> Result<(), EditError>
Apply an edit, recording it for undo if it changed anything.
§Errors
Propagates EditError from EditProject::apply. On error the
project is left unchanged (the operation runs on a clone that is
discarded).
Trait Implementations§
Auto Trait Implementations§
impl Freeze for History
impl RefUnwindSafe for History
impl Send for History
impl Sync for History
impl Unpin for History
impl UnsafeUnpin for History
impl UnwindSafe for History
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
Mutably borrows from an owned value. Read more