pub trait StorageBackend: Send + Sync {
// Required methods
fn collection(&self, name: &str) -> Arc<dyn Collection>;
fn list_collections(&self) -> Vec<String>;
fn flush(&self) -> Result<(), Error>;
fn close(self) -> Result<(), Error>;
}Expand description
Main storage backend trait
Implementations provide access to collections and manage the underlying storage. All implementations must be thread-safe (Send + Sync).
§Implementations
- AutomergeStore: Automerge CRDT with redb persistence (production)
- InMemoryBackend: In-memory store for testing
§Thread Safety
All methods are safe to call from multiple threads. Implementations should use appropriate synchronization (Arc, RwLock, etc.) as needed.
Required Methods§
Sourcefn collection(&self, name: &str) -> Arc<dyn Collection>
fn collection(&self, name: &str) -> Arc<dyn Collection>
Get or create a collection by name
Collections are logical groupings of documents (e.g., “cells”, “nodes”). Multiple calls with the same name return references to the same collection.
§Arguments
name- Collection name (e.g., “cells”, “nodes”, “capabilities”)
§Returns
A thread-safe collection handle
§Example
ⓘ
let cells = storage.collection("cells");
let nodes = storage.collection("nodes");Sourcefn list_collections(&self) -> Vec<String>
fn list_collections(&self) -> Vec<String>
List all collection names
Returns names of all collections that have been created or contain documents.
§Returns
Vector of collection names (may be empty)
Implementors§
impl StorageBackend for AutomergeBackend
Available on crate feature
automerge-backend only.