Struct crdts::mvreg::MVReg

source ·
pub struct MVReg<V, A: Ord> { /* private fields */ }
Expand description

MVReg (Multi-Value Register) On concurrent writes, we will keep all values for which we can’t establish a causal history.

use crdts::{CmRDT, MVReg, Dot, VClock};
let mut r1 = MVReg::new();
let mut r2 = r1.clone();
let r1_read_ctx = r1.read();
let r2_read_ctx = r2.read();

r1.apply(r1.write("bob", r1_read_ctx.derive_add_ctx(123)));

let op = r2.write("alice", r2_read_ctx.derive_add_ctx(111));
r2.apply(op.clone());

r1.apply(op); // we replicate op to r1

// Since "bob" and "alice" were added concurrently, we see both on read
assert_eq!(r1.read().val, vec!["bob", "alice"]);

Implementations§

source§

impl<V, A: Ord + Clone + Debug> MVReg<V, A>

source

pub fn new() -> Self

Construct a new empty MVReg

source

pub fn write(&self, val: V, ctx: AddCtx<A>) -> Op<V, A>

Set the value of the register

source

pub fn read(&self) -> ReadCtx<Vec<V>, A>where V: Clone,

Consumes the register and returns the values

source

pub fn read_ctx(&self) -> ReadCtx<(), A>

Retrieve the current read context

Trait Implementations§

source§

impl<V: Clone, A: Clone + Ord> Clone for MVReg<V, A>

source§

fn clone(&self) -> MVReg<V, A>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<V, A: Ord> CmRDT for MVReg<V, A>

§

type Op = Op<V, A>

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 = Infallible

The validation error returned by validate_op.
source§

fn validate_op(&self, _op: &Self::Op) -> Result<(), Self::Validation>

Some CRDT’s have stricter requirements on how they must be used. To avoid violating these requirements, CRDT’s provide an interface to optionally validate op’s before they are applied. Read more
source§

fn apply(&mut self, op: Self::Op)

Apply an Op to the CRDT
source§

impl<V, A: Ord> CvRDT for MVReg<V, A>

§

type Validation = Infallible

The validation error returned by validate_merge.
source§

fn validate_merge(&self, _other: &Self) -> Result<(), Self::Validation>

Some CRDT’s have stricter requirements on how they must be used. To avoid violating these requirements, CRDT’s provide an interface to optionally validate merge compatibility before attempting to merge. Read more
source§

fn merge(&mut self, other: Self)

Merge the given CRDT into the current CRDT.
source§

impl<V: Debug, A: Debug + Ord> Debug for MVReg<V, A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<V, A: Ord> Default for MVReg<V, A>

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl<'de, V, A> Deserialize<'de> for MVReg<V, A>where V: Deserialize<'de>, A: Deserialize<'de> + Ord,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<V: Display, A: Ord + Display> Display for MVReg<V, A>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<V: PartialEq, A: Ord> PartialEq<MVReg<V, A>> for MVReg<V, A>

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<V, A: Ord> ResetRemove<A> for MVReg<V, A>

source§

fn reset_remove(&mut self, clock: &VClock<A>)

Remove data that is strictly smaller than this clock
source§

impl<V, A> Serialize for MVReg<V, A>where V: Serialize, A: Serialize + Ord,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<V: Eq, A: Ord> Eq for MVReg<V, A>

Auto Trait Implementations§

§

impl<V, A> RefUnwindSafe for MVReg<V, A>where A: RefUnwindSafe, V: RefUnwindSafe,

§

impl<V, A> Send for MVReg<V, A>where A: Send, V: Send,

§

impl<V, A> Sync for MVReg<V, A>where A: Sync, V: Sync,

§

impl<V, A> Unpin for MVReg<V, A>where V: Unpin,

§

impl<V, A> UnwindSafe for MVReg<V, A>where A: RefUnwindSafe, V: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<A, T> Val<A> for Twhere A: Ord, T: Clone + Default + ResetRemove<A> + CmRDT,