Skip to main content

Crdt

Trait Crdt 

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

Source

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.

Source

fn apply_delta(&mut self, delta: Self::Delta)

Provided Methods§

Source

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.

Implementors§

Source§

impl Crdt for GCounter

Source§

impl Crdt for PnCounter

Source§

impl<K: Ord + Clone> Crdt for EnableWinsFlag<K>

Source§

impl<K: Ord + Clone, V: Ord + Clone> Crdt for LwwMap<K, V>

Source§

impl<P: Ord + Clone, V: Ord + Clone> Crdt for Rga<P, V>

Source§

type Delta = RgaDelta<P, V>

Source§

impl<T: Ord + Clone> Crdt for GSet<T>

Source§

type Delta = T

Source§

impl<T: Ord + Clone, K: Ord + Clone> Crdt for OrSet<T, K>

Source§

impl<V: Ord + Clone> Crdt for LwwRegister<V>