Skip to main content

EventLog

Trait EventLog 

Source
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 method
    fn append_events_batch(
        &mut self,
        events: Vec<MemoryEvent>,
    ) -> ThingdResult<Vec<MemoryEvent>> { ... }
}
Expand description

Append-only event log operations.

§Examples

use thingd_core::{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§

Source

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.

Source

fn list_events( &self, stream: Option<&str>, options: ListEventsOptions, ) -> ThingdResult<Vec<MemoryEvent>>

List events, optionally filtered by stream, with pagination.

§Errors

Returns an error when the backing store cannot read events.

Source

fn count_events(&self) -> ThingdResult<u64>

Count total events across all streams.

§Errors

Returns an error when the backing store cannot count events.

Source

fn list_streams(&self) -> ThingdResult<Vec<String>>

List all unique stream names.

§Errors

Returns an error when the backing store cannot list streams.

Provided Methods§

Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§