Struct crdts::lwwreg::LWWReg[][src]

pub struct LWWReg<V, M> {
    pub val: V,
    pub marker: M,
}

LWWReg is a simple CRDT that contains an arbitrary value along with an Ord that tracks causality. It is the responsibility of the user to guarantee that the source of the causal element is monotonic. Don’t use timestamps unless you are comfortable with divergence.

M is a marker. It must grow monotonically and must be globally unique

Fields

val: V

val is the opaque element contained within this CRDT

marker: M

marker should be a monotonic value associated with this val

Implementations

impl<V: PartialEq, M: Ord> LWWReg<V, M>[src]

pub fn update(&mut self, val: V, marker: M)[src]

Updates value witnessed by the given marker.

use crdts::LWWReg;
let mut reg = LWWReg { val: 1, marker: 2 };

// updating with a smaller marker is a no-op
reg.update(2, 1);
assert_eq!(reg.val, 1);

// updating with larger marker succeeds
reg.update(2, 3);
assert_eq!(reg, LWWReg { val: 2, marker: 3 });

pub fn validate_update(&self, val: &V, marker: &M) -> Result<(), Validation>[src]

An update is invalid if the marker is exactly the same as the current marker BUT the value is different:

use crdts::{lwwreg, LWWReg};
let mut reg = LWWReg { val: 1, marker: 2 };

// updating with a smaller marker is a no-op
assert_eq!(reg.validate_update(&32, &2), Err(lwwreg::Validation::ConflictingMarker));

Trait Implementations

impl<V: Clone, M: Clone> Clone for LWWReg<V, M>[src]

impl<V: PartialEq, M: Ord> CmRDT for LWWReg<V, M>[src]

type Op = Self

Op defines a mutation to the CRDT. As long as Op’s from one actor are replayed in exactly the same order they were generated by that actor, the CRDT will converge. In other words, we must have a total ordering on each actors operations, while requiring only a partial order over all ops. E.g. Read more

type Validation = Validation

The validation error returned by validate_op.

impl<V: PartialEq, M: Ord> CvRDT for LWWReg<V, M>[src]

type Validation = Validation

The validation error returned by validate_merge.

fn validate_merge(&self, other: &Self) -> Result<(), Self::Validation>[src]

Validates whether a merge is safe to perfom

Returns an error if the marker is identical but the contained element is different.

use crdts::{lwwreg, LWWReg, CvRDT};
let mut l1 = LWWReg { val: 1, marker: 2 };
let l2 = LWWReg { val: 3, marker: 2 };
// errors!
assert_eq!(l1.validate_merge(&l2), Err(lwwreg::Validation::ConflictingMarker));

fn merge(&mut self, _: Self)[src]

Combines two LWWReg instances according to the marker that tracks causality.

impl<V: Debug, M: Debug> Debug for LWWReg<V, M>[src]

impl<V: Default, M: Default> Default for LWWReg<V, M>[src]

impl<'de, V, M> Deserialize<'de> for LWWReg<V, M> where
    V: Deserialize<'de>,
    M: Deserialize<'de>, 
[src]

impl<V: Eq, M: Eq> Eq for LWWReg<V, M>[src]

impl<V: Hash, M: Hash> Hash for LWWReg<V, M>[src]

impl<V: PartialEq, M: PartialEq> PartialEq<LWWReg<V, M>> for LWWReg<V, M>[src]

impl<V, M> Serialize for LWWReg<V, M> where
    V: Serialize,
    M: Serialize
[src]

impl<V, M> StructuralEq for LWWReg<V, M>[src]

impl<V, M> StructuralPartialEq for LWWReg<V, M>[src]

Auto Trait Implementations

impl<V, M> RefUnwindSafe for LWWReg<V, M> where
    M: RefUnwindSafe,
    V: RefUnwindSafe

impl<V, M> Send for LWWReg<V, M> where
    M: Send,
    V: Send

impl<V, M> Sync for LWWReg<V, M> where
    M: Sync,
    V: Sync

impl<V, M> Unpin for LWWReg<V, M> where
    M: Unpin,
    V: Unpin

impl<V, M> UnwindSafe for LWWReg<V, M> where
    M: UnwindSafe,
    V: 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> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[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.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,