pub trait Storage: Send + Sync {
// Required methods
fn save(&mut self, key: &str, data: Vec<u8>) -> Result<()>;
fn load(&self, key: &str) -> Result<Option<Vec<u8>>>;
fn delete(&mut self, key: &str) -> Result<()>;
fn list_keys(&self) -> Result<Vec<String>>;
// Provided methods
fn begin_transaction(&mut self) -> Result<()> { ... }
fn commit_transaction(&mut self) -> Result<()> { ... }
fn rollback_transaction(&mut self) -> Result<()> { ... }
}Expand description
Storage backend trait for persisting event data.
Implementations must be thread-safe (Send + Sync) and handle serialization/deserialization of event data.
The save method takes ownership of data to avoid redundant copies.
Most storage backends need to own the data anyway, so this provides
better symmetry with load() and eliminates an extra allocation.
§Transaction Support
Storage backends can optionally implement atomic multi-operation transactions
via begin_transaction(), commit_transaction(), and rollback_transaction().
Backends that don’t support transactions use the default no-op implementations.
When transactions are supported:
begin_transaction()starts a new transaction- All
save()anddelete()calls are buffered until commit commit_transaction()atomically applies all changesrollback_transaction()discards pending changes
Backends must be either in transaction mode or normal mode - mixing operations across modes should return an error.
Required Methods§
fn save(&mut self, key: &str, data: Vec<u8>) -> Result<()>
fn load(&self, key: &str) -> Result<Option<Vec<u8>>>
fn delete(&mut self, key: &str) -> Result<()>
fn list_keys(&self) -> Result<Vec<String>>
Provided Methods§
Sourcefn begin_transaction(&mut self) -> Result<()>
fn begin_transaction(&mut self) -> Result<()>
Begins a transaction. All subsequent save/delete operations are buffered until commit_transaction() is called.
Default implementation is a no-op for backends that don’t support transactions.
Sourcefn commit_transaction(&mut self) -> Result<()>
fn commit_transaction(&mut self) -> Result<()>
Commits the current transaction, atomically applying all buffered changes.
Default implementation is a no-op for backends that don’t support transactions.
Sourcefn rollback_transaction(&mut self) -> Result<()>
fn rollback_transaction(&mut self) -> Result<()>
Rolls back the current transaction, discarding all buffered changes.
Default implementation is a no-op for backends that don’t support transactions.