Skip to main content

StorageBackend

Trait StorageBackend 

Source
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§

Source

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");
Source

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)

Source

fn flush(&self) -> Result<(), Error>

Flush any pending writes to disk

For in-memory backends, this is a no-op. For persistent backends (RocksDB), this ensures all writes are durable.

§Returns

Ok(()) on success, Err if flush fails

Source

fn close(self) -> Result<(), Error>

Close the storage backend cleanly

Implementations should flush pending writes and release resources. After calling close(), the backend should not be used.

§Returns

Ok(()) on success, Err if close fails

Implementors§

Source§

impl StorageBackend for AutomergeBackend

Available on crate feature automerge-backend only.