pub struct EventStore { /* private fields */ }Expand description
Thread-safe event store for SSE resumability.
Stores events per stream with automatic expiration and size limits. Use this to enable clients to resume SSE streams after disconnection.
§Thread Safety
The EventStore uses RwLock internally and is safe for concurrent
access from multiple threads.
Implementations§
Source§impl EventStore
impl EventStore
Sourcepub fn new() -> EventStore
pub fn new() -> EventStore
Creates a new event store with default configuration.
Sourcepub fn with_config(config: EventStoreConfig) -> EventStore
pub fn with_config(config: EventStoreConfig) -> EventStore
Creates a new event store with custom configuration.
Sourcepub fn config(&self) -> &EventStoreConfig
pub fn config(&self) -> &EventStoreConfig
Returns the configuration.
Sourcepub fn store_priming_event(&self, stream_id: &str) -> String
pub fn store_priming_event(&self, stream_id: &str) -> String
Stores a priming event (empty data) for SSE initialization.
Per SSE spec, servers should send an event with just an ID to prime
the client’s Last-Event-ID tracking.
Sourcepub fn get_events_after(
&self,
stream_id: &str,
after_id: Option<&str>,
) -> Vec<EventEntry>
pub fn get_events_after( &self, stream_id: &str, after_id: Option<&str>, ) -> Vec<EventEntry>
Sourcepub fn replay_events_after<F>(
&self,
last_event_id: &str,
callback: F,
) -> Option<String>where
F: FnMut(&EventEntry),
pub fn replay_events_after<F>(
&self,
last_event_id: &str,
callback: F,
) -> Option<String>where
F: FnMut(&EventEntry),
Replays events after a specific event ID using a callback.
This is the primary method for SSE resumption. When a client reconnects
with a Last-Event-ID, use this to replay missed events.
§Arguments
last_event_id- The client’s last received event IDcallback- Called for each event to replay
§Returns
The stream ID if the event was found, None otherwise.
Sourcepub fn find_stream_for_event(&self, event_id: &str) -> Option<String>
pub fn find_stream_for_event(&self, event_id: &str) -> Option<String>
Looks up the stream ID for a given event ID.
§Returns
The stream ID if the event exists, None otherwise.
Sourcepub fn clear_stream(&self, stream_id: &str)
pub fn clear_stream(&self, stream_id: &str)
Removes all events for a stream.
Call this when a session ends to free memory.
Sourcepub fn cleanup_expired(&self)
pub fn cleanup_expired(&self)
Removes all expired events across all streams.
This is called automatically during operations, but you can call it manually for cleanup.
Sourcepub fn stream_count(&self) -> usize
pub fn stream_count(&self) -> usize
Returns the number of streams currently stored.
Sourcepub fn event_count(&self) -> usize
pub fn event_count(&self) -> usize
Returns the total number of events across all streams.
Sourcepub fn stats(&self) -> EventStoreStats
pub fn stats(&self) -> EventStoreStats
Returns statistics about the event store.
Trait Implementations§
Source§impl Debug for EventStore
impl Debug for EventStore
Source§impl Default for EventStore
impl Default for EventStore
Source§fn default() -> EventStore
fn default() -> EventStore
Auto Trait Implementations§
impl !Freeze for EventStore
impl RefUnwindSafe for EventStore
impl Send for EventStore
impl Sync for EventStore
impl Unpin for EventStore
impl UnsafeUnpin for EventStore
impl UnwindSafe for EventStore
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more