[−][src]Struct cvrdt_exposition::lww_register::LWWRegister
A last-write-wins register
Panics
Any attempt to add
a new element to this register will panic if the register's timestamp
is
greater than Instant::now()
(no time-traveling allowed) at the time of calling add
:
// this will panic use std::time::{Duration, Instant}; use cvrdt_exposition::{Grow, LWWRegister}; let mut x = LWWRegister::new(('a', Instant::now() + Duration::from_secs(1729))); x.add('b');
Difference from references
In the comprehensive study paper, timestamps are
unsigned integers, whereas we use
std::time::Instant
s.
Examples
Example usage, including demonstrating some properties:
use std::time::Instant; use cvrdt_exposition::{Grow, LWWRegister}; let mut x = LWWRegister::new(('a', Instant::now())); x.add('b'); x.add('c'); assert_eq!(x.query(&()), 'c'); let y = LWWRegister::new(('z', Instant::now())); assert!(x.le(&y)); let z = x.merge(&y); assert_eq!(y.merge(&x).payload(), z.payload()); assert_eq!(z.query(&()), 'z'); assert_eq!(z.payload().0, 'z');
Fields
value: X
The value saved in this register
timestamp: Instant
The time when this register was last saved
Trait Implementations
impl<X: Clone + Eq> Clone for LWWRegister<X>
[src]
fn clone(&self) -> LWWRegister<X>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<X: Debug + Clone + Eq> Debug for LWWRegister<X>
[src]
impl<X: Clone + Eq> Grow for LWWRegister<X>
[src]
type Payload = (X, Instant)
The internal state of our CvRDT; sufficient to build a new copy via new
. Required to implement Eq
for testing and verification. Read more
type Update = X
Message to update our internal state
type Query = ()
Message to query the Value
of our CvRDT
type Value = X
The response to a Query
fn new(payload: Self::Payload) -> Self
[src]
fn payload(&self) -> Self::Payload
[src]
fn add(&mut self, update: Self::Update)
[src]
fn le(&self, other: &Self) -> bool
[src]
fn merge(&self, other: &Self) -> Self
[src]
fn query(&self, _query: &Self::Query) -> Self::Value
[src]
Auto Trait Implementations
impl<X> RefUnwindSafe for LWWRegister<X> where
X: RefUnwindSafe,
X: RefUnwindSafe,
impl<X> Send for LWWRegister<X> where
X: Send,
X: Send,
impl<X> Sync for LWWRegister<X> where
X: Sync,
X: Sync,
impl<X> Unpin for LWWRegister<X> where
X: Unpin,
X: Unpin,
impl<X> UnwindSafe for LWWRegister<X> where
X: UnwindSafe,
X: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,