pub struct MVRegister<T: Clone + Ord> { /* private fields */ }Expand description
A multi-value register (MV-Register).
Unlike LWW-Register, this preserves all concurrently written values. When concurrent writes occur, all values are kept until a subsequent write supersedes them. This is useful when you want to detect conflicts rather than silently resolving them.
§Example
use crdt_kit::prelude::*;
let mut r1 = MVRegister::new("node-1");
r1.set("alice");
let mut r2 = MVRegister::new("node-2");
r2.set("bob");
r1.merge(&r2);
// Both values are preserved as concurrent writes
let values = r1.values();
assert!(values.contains(&&"alice"));
assert!(values.contains(&&"bob"));Implementations§
Source§impl<T: Clone + Ord> MVRegister<T>
impl<T: Clone + Ord> MVRegister<T>
Sourcepub fn new(actor: impl Into<String>) -> Self
pub fn new(actor: impl Into<String>) -> Self
Create a new empty MV-Register for the given actor.
Sourcepub fn values(&self) -> Vec<&T>
pub fn values(&self) -> Vec<&T>
Get all current values.
Returns a single value during normal operation, or multiple values when concurrent writes have been merged without a subsequent write.
Sourcepub fn is_conflicted(&self) -> bool
pub fn is_conflicted(&self) -> bool
Returns true if there are concurrent (conflicting) values.
Trait Implementations§
Source§impl<T: Clone + Clone + Ord> Clone for MVRegister<T>
impl<T: Clone + Clone + Ord> Clone for MVRegister<T>
Source§fn clone(&self) -> MVRegister<T>
fn clone(&self) -> MVRegister<T>
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 moreimpl<T: Eq + Clone + Ord> Eq for MVRegister<T>
impl<T: Clone + Ord> StructuralPartialEq for MVRegister<T>
Auto Trait Implementations§
impl<T> Freeze for MVRegister<T>
impl<T> RefUnwindSafe for MVRegister<T>where
T: RefUnwindSafe,
impl<T> Send for MVRegister<T>where
T: Send,
impl<T> Sync for MVRegister<T>where
T: Sync,
impl<T> Unpin for MVRegister<T>where
T: Unpin,
impl<T> UnwindSafe for MVRegister<T>where
T: UnwindSafe,
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