pub trait TypedCollection<M>: Send + Sync{
// Required methods
fn upsert(&self, doc_id: &str, message: &M) -> Result<()>;
fn get(&self, doc_id: &str) -> Result<Option<M>>;
fn delete(&self, doc_id: &str) -> Result<()>;
fn scan(&self) -> Result<Vec<(String, M)>>;
fn find(
&self,
predicate: Box<dyn Fn(&M) -> bool + Send>,
) -> Result<Vec<(String, M)>>;
fn count(&self) -> Result<usize>;
}Expand description
Typed collection trait for CRDT-optimized storage
Backends that implement CrdtCapable provide this trait to enable
field-level conflict resolution via CRDT semantics.
§Type Parameters
M- Protobuf message type with serde support
§CRDT Semantics
Different field types get different CRDT semantics:
- Arrays: OR-Set (observed-remove set) - concurrent additions merge
- Scalars: LWW-Register (last-write-wins) - timestamp-based resolution
- Nested objects: Recursive application of above rules
§Example
ⓘ
use peat_protocol::storage::{CrdtCapable, TypedCollection};
use peat_schema::hierarchy::v1::SquadSummary;
let backend = AutomergeIrohBackend::new(config);
let squads: Arc<dyn TypedCollection<SquadSummary>> =
backend.typed_collection("squads");
// Field-level updates
let mut summary = squads.get("squad-1")?.unwrap();
summary.member_ids.push("node-4".to_string()); // OR-Set addition
squads.upsert("squad-1", &summary)?;
// → Only member_ids field is transmitted, not entire documentRequired Methods§
Sourcefn upsert(&self, doc_id: &str, message: &M) -> Result<()>
fn upsert(&self, doc_id: &str, message: &M) -> Result<()>
Insert or update a typed document with CRDT merging
Backends convert the message to their CRDT format:
- Automerge:
message→ Automerge document
Implementors§
impl<M> TypedCollection<M> for AutomergeTypedCollection<M>
Available on crate feature
automerge-backend only.