pub trait Crdt: Mergeable {
type Delta;
// Required methods
fn validate_record(
&self,
id: RecordId,
delta: &Self::Delta,
) -> Result<(), WireError>;
fn apply_delta(&mut self, delta: Self::Delta);
// Provided method
fn replica_count(&self) -> Option<usize> { ... }
}Expand description
Delta application surface for CRDT product types.
Every implementation, including user-defined types, must explicitly provide
Crdt::validate_record. The compiler checks its presence; behavioral tests
must check its contract (the merge laws alone do not establish admission).
An implementation in another module cannot inherit permissive admission:
mod downstream {
use safemesh_crdt::{Crdt, Mergeable};
pub struct MissingValidation;
impl Mergeable for MissingValidation {
fn merge(&mut self, _: &Self) -> Result<(), safemesh_crdt::MergeError> {
Ok(())
}
}
impl Crdt for MissingValidation {
type Delta = ();
fn apply_delta(&mut self, _: ()) {}
}
}Required Associated Types§
Required Methods§
Sourcefn validate_record(
&self,
id: RecordId,
delta: &Self::Delta,
) -> Result<(), WireError>
fn validate_record( &self, id: RecordId, delta: &Self::Delta, ) -> Result<(), WireError>
Validate a decoded record before admission or replay into this carrier.
Refuse records outside the carrier’s shape or ownership domain: no carrier of that same shape may legitimately apply such a record. For example, a fixed-width counter refuses an out-of-range coordinate or a coordinate belonging to a different record author.
Accept legitimate replay even when the current state absorbs the delta
(duplicates, lower tallies, losing writes, or existing tombstones). On a
fresh carrier of the same shape, it must yield the state the record
denotes, including lattice bottom for an empty remove. A lack of visible
change is not evidence of invalidity. Types with a total typed delta
domain may explicitly return Ok(()); they have no domain refusal case.
This check must not mutate state. Wire decoding and log-shape validation
are separate checks performed before this method.
fn apply_delta(&mut self, delta: Self::Delta)
Provided Methods§
Sourcefn replica_count(&self) -> Option<usize>
fn replica_count(&self) -> Option<usize>
Fixed replica domain, or None for CRDTs without a fixed arity.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.