pub trait DurableSink:
Send
+ Sync
+ 'static {
// Required method
fn write(&self, event: &SessionEvent) -> Result<()>;
}Expand description
A write-ahead sink for durable SessionEvents.
Implementors are responsible for persisting or queueing the event
before returning from DurableSink::write. Errors must be reported
through the returned Result so callers can fall back to logging —
never swallow durable-write failures silently.
§Thread-safety
Implementations must be Send + Sync + 'static and are shared behind
Arc. Interior mutability (e.g. tokio::sync::Mutex) is the
implementor’s responsibility.
§Examples
A minimal in-memory sink useful in tests:
use std::sync::{Arc, Mutex};
use codetether_agent::session::{DurableSink, SessionEvent};
struct Collector(Arc<Mutex<Vec<String>>>);
impl DurableSink for Collector {
fn write(&self, event: &SessionEvent) -> std::io::Result<()> {
self.0.lock().unwrap().push(format!("{event:?}"));
Ok(())
}
}
let c = Collector(Arc::new(Mutex::new(Vec::new())));
c.write(&SessionEvent::Done).unwrap();