pub struct ConflictResolver { /* private fields */ }Expand description
Handles conflict resolution using Diamond-Types CRDT.
The conflict resolver intercepts updates marked with merge-type: "diamond",
applies them to the appropriate resource’s CRDT, and returns the merged result.
This ensures deterministic convergence across all peers.
§Request/Response Formats
Plain Text Updates:
- Inserts text at position 0
- Body can be plain text or JSON
Structured JSON Updates:
"inserts": Array of{pos, text}objects"deletes": Array of{start, end}objects- All operations are applied and merged into the CRDT
Implementations§
Source§impl ConflictResolver
impl ConflictResolver
Sourcepub fn new(resource_manager: ResourceStateManager) -> Self
pub fn new(resource_manager: ResourceStateManager) -> Self
Create a new conflict resolver with the given resource manager.
§Arguments
resource_manager- The centralized resource state registry
§Examples
ⓘ
use crate::core::server::{ConflictResolver, ResourceStateManager};
let manager = ResourceStateManager::new();
let resolver = ConflictResolver::new(manager);Sourcepub async fn resolve_update(
&self,
resource_id: &str,
update: &Update,
agent_id: &str,
) -> Result<Update, String>
pub async fn resolve_update( &self, resource_id: &str, update: &Update, agent_id: &str, ) -> Result<Update, String>
Resolve an update by applying CRDT semantics if needed.
If the update has merge-type: "diamond", it’s applied to the resource’s CRDT.
Otherwise, the update is returned unchanged (no merge strategy applied).
§Arguments
resource_id- The resource being updatedupdate- The incoming Braid updateagent_id- Origin agent identifier
§Returns
The resolved update with merged content and current version.
§Examples
ⓘ
let resolver = ConflictResolver::new(manager);
let update = Update::snapshot(Version::new("v1"), "hello")
.with_merge_type("diamond");
let result = resolver.resolve_update("doc1", &update, "alice").await?;Sourcepub async fn get_history(
&self,
resource_id: &str,
since_versions: &[&str],
) -> Result<Vec<Update>, String>
pub async fn get_history( &self, resource_id: &str, since_versions: &[&str], ) -> Result<Vec<Update>, String>
Retrieve history for a resource since specific versions.
Sourcepub fn get_resource_content(&self, resource_id: &str) -> Option<String>
pub fn get_resource_content(&self, resource_id: &str) -> Option<String>
Trait Implementations§
Source§impl Clone for ConflictResolver
impl Clone for ConflictResolver
Source§fn clone(&self) -> ConflictResolver
fn clone(&self) -> ConflictResolver
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ConflictResolver
impl !RefUnwindSafe for ConflictResolver
impl Send for ConflictResolver
impl Sync for ConflictResolver
impl Unpin for ConflictResolver
impl !UnwindSafe for ConflictResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more