pub trait EventLog {
// Required methods
fn append_event(&mut self, event: MemoryEvent) -> ThingdResult<MemoryEvent>;
fn list_events(
&self,
stream: Option<&str>,
options: ListEventsOptions,
) -> ThingdResult<Vec<MemoryEvent>>;
fn count_events(&self) -> ThingdResult<u64>;
fn list_streams(&self) -> ThingdResult<Vec<String>>;
// Provided methods
fn is_protected_stream(&self, stream: &str) -> bool { ... }
fn append_events_batch(
&mut self,
events: Vec<MemoryEvent>,
) -> ThingdResult<Vec<MemoryEvent>> { ... }
fn delete_last_event(
&mut self,
stream: &str,
) -> ThingdResult<Option<MemoryEvent>> { ... }
fn delete_stream(&mut self, stream: &str) -> ThingdResult<u64> { ... }
}Expand description
Append-only event log operations.
§Examples
use thingd::{MemoryEngine, EventLog, MemoryEvent, ListEventsOptions};
let mut store = MemoryEngine::new();
let event = MemoryEvent::new("audit", "user.created", r#"{"user":"alice"}"#);
store.append_event(event).unwrap();
let events = store.list_events(None, ListEventsOptions::default()).unwrap();
assert_eq!(events.len(), 1);
assert_eq!(events[0].event_type, "user.created");Required Methods§
Sourcefn append_event(&mut self, event: MemoryEvent) -> ThingdResult<MemoryEvent>
fn append_event(&mut self, event: MemoryEvent) -> ThingdResult<MemoryEvent>
Append an event to a stream.
§Errors
Returns an error when the backing store cannot append the event.
Sourcefn list_events(
&self,
stream: Option<&str>,
options: ListEventsOptions,
) -> ThingdResult<Vec<MemoryEvent>>
fn list_events( &self, stream: Option<&str>, options: ListEventsOptions, ) -> ThingdResult<Vec<MemoryEvent>>
List events, optionally filtered by stream, with pagination.
Events are returned in ascending sequence order (oldest first).
§Errors
Returns an error when the backing store cannot read events.
Sourcefn count_events(&self) -> ThingdResult<u64>
fn count_events(&self) -> ThingdResult<u64>
Count total events across all streams.
§Errors
Returns an error when the backing store cannot count events.
Sourcefn list_streams(&self) -> ThingdResult<Vec<String>>
fn list_streams(&self) -> ThingdResult<Vec<String>>
Provided Methods§
Sourcefn is_protected_stream(&self, stream: &str) -> bool
fn is_protected_stream(&self, stream: &str) -> bool
Returns true if the stream is protected from deletion and external
mutation. Protected streams (e.g. "__thingd:mcp:audit") reject
delete_last_event and delete_stream calls.
Sourcefn append_events_batch(
&mut self,
events: Vec<MemoryEvent>,
) -> ThingdResult<Vec<MemoryEvent>>
fn append_events_batch( &mut self, events: Vec<MemoryEvent>, ) -> ThingdResult<Vec<MemoryEvent>>
Append multiple events to a stream in a single transaction.
This is significantly faster than calling append_event in a loop.
§Errors
Returns an error when the backing store cannot append any event.
Sourcefn delete_last_event(
&mut self,
stream: &str,
) -> ThingdResult<Option<MemoryEvent>>
fn delete_last_event( &mut self, stream: &str, ) -> ThingdResult<Option<MemoryEvent>>
Delete the most recent event from a stream.
Returns the deleted event, or None if the stream was empty or
did not exist. This is useful for implementing undo patterns in
event-sourced applications.
Returns ThingdError::Protected when the stream is protected.
§Errors
Returns an error when the backing store cannot delete the event.
Sourcefn delete_stream(&mut self, stream: &str) -> ThingdResult<u64>
fn delete_stream(&mut self, stream: &str) -> ThingdResult<u64>
Delete all events in a stream.
Returns the number of events deleted. This is useful for cleaning up completed or expired event streams (e.g. finished game matches).
Returns ThingdError::Protected when the stream is protected.
§Errors
Returns an error when the backing store cannot delete the events.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementors§
impl EventLog for MemoryEngine
impl EventLog for SqliteThingStore
sqlite only.