Skip to main content

EventLog

Struct EventLog 

Source
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>

Source

pub fn new() -> Self

Creates a new empty EventLog.

Source

pub fn append(&mut self, event: T)

Appends an event, truncating any redo history beyond the cursor.

Source

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

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn cursor(&self) -> usize

Returns the current cursor position (one past last applied event).

Source

pub fn length(&self) -> usize

Returns the total number of entries in the log (including checkpoints).

Source

pub fn can_undo(&self) -> bool

Returns whether there are events before the cursor that can be undone.

Source

pub fn can_redo(&self) -> bool

Returns whether there are events after the cursor that can be redone.

Trait Implementations§

Source§

impl<T: Clone> Default for EventLog<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for EventLog<T>

§

impl<T> RefUnwindSafe for EventLog<T>
where T: RefUnwindSafe,

§

impl<T> Send for EventLog<T>
where T: Send,

§

impl<T> Sync for EventLog<T>
where T: Sync,

§

impl<T> Unpin for EventLog<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for EventLog<T>

§

impl<T> UnwindSafe for EventLog<T>
where T: UnwindSafe,

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.