Struct crdts::orswot::Orswot

source ·
pub struct Orswot<M: Hash + Eq, A: Ord + Hash> { /* private fields */ }
Expand description

Orswot is an add-biased or-set without tombstones ported from the riak_dt CRDT library.

Implementations§

source§

impl<M: Hash + Clone + Eq, A: Ord + Hash + Clone> Orswot<M, A>

source

pub fn new() -> Self

Returns a new Orswot instance.

source

pub fn clock(&self) -> VClock<A>

Return a snapshot of the ORSWOT clock

source

pub fn add(&self, member: M, ctx: AddCtx<A>) -> Op<M, A>

Add a single element.

source

pub fn add_all<I: IntoIterator<Item = M>>( &self, members: I, ctx: AddCtx<A> ) -> Op<M, A>

Add multiple elements.

source

pub fn rm(&self, member: M, ctx: RmCtx<A>) -> Op<M, A>

Remove a member with a witnessing ctx.

source

pub fn rm_all<I: IntoIterator<Item = M>>( &self, members: I, ctx: RmCtx<A> ) -> Op<M, A>

Remove members with a witnessing ctx.

source

pub fn contains(&self, member: &M) -> ReadCtx<bool, A>

Check if the set contains a member

source

pub fn iter(&self) -> impl Iterator<Item = ReadCtx<&M, A>>

Gets an iterator over the entries of the Map.

Examples
use crdts::{Orswot, CmRDT};

let actor = "actor";

let mut set: Orswot<u8, &'static str> = Default::default();

let add_ctx = set.read_ctx().derive_add_ctx(actor);
set.apply(set.add(100, add_ctx));

let add_ctx = set.read_ctx().derive_add_ctx(actor);
set.apply(set.add(50, add_ctx));

let mut items: Vec<_> = set
    .iter()
    .map(|item_ctx| *item_ctx.val)
    .collect();

items.sort();

assert_eq!(items, &[50, 100]);
source

pub fn read(&self) -> ReadCtx<HashSet<M>, A>

Retrieve the current members.

source

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

Retrieve the current read context

Trait Implementations§

source§

impl<M: Clone + Hash + Eq, A: Clone + Ord + Hash> Clone for Orswot<M, A>

source§

fn clone(&self) -> Orswot<M, 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<M: Hash + Clone + Eq, A: Ord + Hash + Clone + Debug> CmRDT for Orswot<M, A>

§

type Op = Op<M, 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 = <VClock<A> as CmRDT>::Validation

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<M: Hash + Eq + Clone + Debug, A: Ord + Hash + Clone + Debug> CvRDT for Orswot<M, A>

source§

fn merge(&mut self, other: Self)

Merge combines another Orswot with this one.

§

type Validation = Validation<M, A>

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§

impl<M: Debug + Hash + Eq, A: Debug + Ord + Hash> Debug for Orswot<M, A>

source§

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

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

impl<M: Hash + Eq, A: Ord + Hash> Default for Orswot<M, A>

source§

fn default() -> Self

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

impl<'de, M, A> Deserialize<'de> for Orswot<M, A>where M: Deserialize<'de> + Hash + Eq, A: Deserialize<'de> + Ord + Hash,

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<M: PartialEq + Hash + Eq, A: PartialEq + Ord + Hash> PartialEq<Orswot<M, A>> for Orswot<M, A>

source§

fn eq(&self, other: &Orswot<M, A>) -> 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<M: Hash + Clone + Eq, A: Ord + Hash> ResetRemove<A> for Orswot<M, A>

source§

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

Remove data that is strictly smaller than this clock
source§

impl<M, A> Serialize for Orswot<M, A>where M: Serialize + Hash + Eq, A: Serialize + Ord + Hash,

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<M: Eq + Hash + Eq, A: Eq + Ord + Hash> Eq for Orswot<M, A>

source§

impl<M: Hash + Eq, A: Ord + Hash> StructuralEq for Orswot<M, A>

source§

impl<M: Hash + Eq, A: Ord + Hash> StructuralPartialEq for Orswot<M, A>

Auto Trait Implementations§

§

impl<M, A> RefUnwindSafe for Orswot<M, A>where A: RefUnwindSafe, M: RefUnwindSafe,

§

impl<M, A> Send for Orswot<M, A>where A: Send, M: Send,

§

impl<M, A> Sync for Orswot<M, A>where A: Sync, M: Sync,

§

impl<M, A> Unpin for Orswot<M, A>where M: Unpin,

§

impl<M, A> UnwindSafe for Orswot<M, A>where A: RefUnwindSafe, M: 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, 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,