pub struct EventLog<T: Clone> { /* private fields */ }Expand description
Generic cursor-based event log with undo/redo and named checkpoints.
Events are appended at the cursor position. The cursor always points one past the last applied event. Undo moves the cursor back; redo moves it forward. Appending a new event truncates the redo tail.
Checkpoint sentinels are stored in the log but skipped during undo/redo traversal.
Implementations§
Source§impl<T: Clone> EventLog<T>
impl<T: Clone> EventLog<T>
Sourcepub fn append(&mut self, event: T)
pub fn append(&mut self, event: T)
Appends an event, truncating any redo history beyond the cursor.
Sourcepub fn checkpoint(&mut self, name: &str)
pub fn checkpoint(&mut self, name: &str)
Creates a named checkpoint at the current cursor position, truncating
any redo tail first (same semantics as append).
Sourcepub fn undo(&mut self, count: usize) -> Vec<T>
pub fn undo(&mut self, count: usize) -> Vec<T>
Undoes up to count non-checkpoint events. Returns events in reverse
order (most recent first) for the caller to reverse-apply.
Sourcepub fn undo_to(&mut self, name: &str) -> Result<Vec<T>, String>
pub fn undo_to(&mut self, name: &str) -> Result<Vec<T>, String>
Undoes to a named checkpoint. Returns events in reverse order. Returns Err if the checkpoint doesn’t exist or is at/beyond cursor.
Sourcepub fn redo(&mut self, count: usize) -> Vec<T>
pub fn redo(&mut self, count: usize) -> Vec<T>
Redoes up to count non-checkpoint events. Returns events in forward
order for the caller to re-apply.
Sourcepub fn recent(&self, count: usize) -> Vec<T>
pub fn recent(&self, count: usize) -> Vec<T>
Returns the last count non-checkpoint events (up to cursor) in
chronological order (oldest first). If count is 0, returns all.
Sourcepub fn cursor(&self) -> usize
pub fn cursor(&self) -> usize
Returns the current cursor position (one past last applied event).
Sourcepub fn length(&self) -> usize
pub fn length(&self) -> usize
Returns the total number of entries in the log (including checkpoints).