[][src]Struct cvrdt_exposition::lww_register::LWWRegister

pub struct LWWRegister<X: Clone + Eq> {
    pub value: X,
    pub timestamp: Instant,
}

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 example panics
// 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::Instants.

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]

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

Auto Trait Implementations

impl<X> RefUnwindSafe for LWWRegister<X> where
    X: RefUnwindSafe

impl<X> Send for LWWRegister<X> where
    X: Send

impl<X> Sync for LWWRegister<X> where
    X: Sync

impl<X> Unpin for LWWRegister<X> where
    X: Unpin

impl<X> UnwindSafe for LWWRegister<X> where
    X: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.