braid-core 0.1.4

Unified Braid Protocol implementation in Rust, including Braid-HTTP, Antimatter CRDT, and BraidFS.
Documentation
use super::messages::Patch;
use std::collections::HashMap;

/// Trait for the underlying CRDT that Antimatter manages.
/// Antimatter handles the networking/metadata and pruning, while this trait
/// handles the actual data application and storage.
pub trait PrunableCrdt {
    /// Apply a patch to the CRDT.
    fn apply_patch(&mut self, patch: Patch);

    /// Prune metadata associated with a version.
    /// This is the core "antimatter" operation.
    fn prune(&mut self, version: &str);

    /// Get the current sequence number or internal state identifier (optional).
    fn get_next_seq(&self) -> u64;

    /// Generate a braid (list of updates) to sync a peer that knows `known_versions`.
    fn generate_braid(
        &self,
        known_versions: &HashMap<String, bool>,
    ) -> Vec<(String, HashMap<String, bool>, Vec<Patch>)>;
}

/// A simple mock implementation for testing/compilation
pub struct MockCrdt;
impl PrunableCrdt for MockCrdt {
    fn apply_patch(&mut self, _patch: Patch) {}
    fn prune(&mut self, _version: &str) {}
    fn get_next_seq(&self) -> u64 {
        0
    }
    fn generate_braid(
        &self,
        _known_versions: &HashMap<String, bool>,
    ) -> Vec<(String, HashMap<String, bool>, Vec<Patch>)> {
        Vec::new()
    }
}