pub struct LWWRegister<T: Clone> { /* private fields */ }Expand description
A last-writer-wins register (LWW-Register).
Resolves concurrent writes by keeping the value with the highest
HybridTimestamp. This provides causally consistent ordering even
with clock drift between nodes.
§Example
use crdt_kit::prelude::*;
use crdt_kit::clock::HybridClock;
let mut clock1 = HybridClock::new(1);
let mut clock2 = HybridClock::new(2);
let mut r1 = LWWRegister::new("hello", &mut clock1);
let mut r2 = LWWRegister::new("world", &mut clock2);
r1.merge(&r2);
// Value is determined by HLC timestamp orderingImplementations§
Source§impl<T: Clone> LWWRegister<T>
impl<T: Clone> LWWRegister<T>
Sourcepub fn new(value: T, clock: &mut HybridClock) -> Self
pub fn new(value: T, clock: &mut HybridClock) -> Self
Create a new LWW-Register with an initial value.
Uses the provided HybridClock for a causally consistent timestamp.
Sourcepub fn with_timestamp(value: T, timestamp: HybridTimestamp) -> Self
pub fn with_timestamp(value: T, timestamp: HybridTimestamp) -> Self
Create a new LWW-Register with an explicit timestamp.
Useful for testing or deserialization.
Sourcepub fn set(&mut self, value: T, clock: &mut HybridClock)
pub fn set(&mut self, value: T, clock: &mut HybridClock)
Update the register’s value.
Uses the provided HybridClock for a causally consistent timestamp.
Sourcepub fn set_with_timestamp(&mut self, value: T, timestamp: HybridTimestamp)
pub fn set_with_timestamp(&mut self, value: T, timestamp: HybridTimestamp)
Update the register’s value with an explicit timestamp.
Only applies if the new timestamp is >= the current one.
Sourcepub fn timestamp(&self) -> HybridTimestamp
pub fn timestamp(&self) -> HybridTimestamp
Get the current timestamp.
Trait Implementations§
Source§impl<T: Clone + Clone> Clone for LWWRegister<T>
impl<T: Clone + Clone> Clone for LWWRegister<T>
Source§fn clone(&self) -> LWWRegister<T>
fn clone(&self) -> LWWRegister<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 moreSource§impl<T: Clone> Crdt for LWWRegister<T>
impl<T: Clone> Crdt for LWWRegister<T>
Source§impl<T: Clone> DeltaCrdt for LWWRegister<T>
impl<T: Clone> DeltaCrdt for LWWRegister<T>
Source§type Delta = LWWRegisterDelta<T>
type Delta = LWWRegisterDelta<T>
The type of delta produced by this CRDT.
Source§fn delta(&self, other: &Self) -> LWWRegisterDelta<T>
fn delta(&self, other: &Self) -> LWWRegisterDelta<T>
Source§fn apply_delta(&mut self, delta: &LWWRegisterDelta<T>)
fn apply_delta(&mut self, delta: &LWWRegisterDelta<T>)
Apply a delta to this replica’s state. Read more
Source§impl<T: Clone> Versioned for LWWRegister<T>
impl<T: Clone> Versioned for LWWRegister<T>
impl<T: Clone + Eq> Eq for LWWRegister<T>
Auto Trait Implementations§
impl<T> Freeze for LWWRegister<T>where
T: Freeze,
impl<T> RefUnwindSafe for LWWRegister<T>where
T: RefUnwindSafe,
impl<T> Send for LWWRegister<T>where
T: Send,
impl<T> Sync for LWWRegister<T>where
T: Sync,
impl<T> Unpin for LWWRegister<T>where
T: Unpin,
impl<T> UnsafeUnpin for LWWRegister<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for LWWRegister<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