Struct crdts::gcounter::GCounter

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

GCounter is a grow-only witnessed counter.

Examples

use crdts::{GCounter, CmRDT};

let mut a = GCounter::new();
let mut b = GCounter::new();

a.apply(a.inc("A"));
b.apply(b.inc("B"));

assert_eq!(a.read(), b.read());

a.apply(a.inc("A"));
assert!(a.read() > b.read());

Implementations§

source§

impl<A: Ord + Clone> GCounter<A>

source

pub fn new() -> Self

Produce a new GCounter.

source

pub fn inc(&self, actor: A) -> Dot<A>

Generate Op to increment the counter.

source

pub fn inc_many(&self, actor: A, steps: u64) -> Dot<A>

Generate Op to increment the counter by a number of steps.

source

pub fn read(&self) -> BigUint

Return the current sum of this counter.

Trait Implementations§

source§

impl<A: Clone + Ord> Clone for GCounter<A>

source§

fn clone(&self) -> GCounter<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<A: Ord + Clone + Debug> CmRDT for GCounter<A>

§

type Op = Dot<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<A: Ord + Clone + Debug> CvRDT for GCounter<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<A: Debug + Ord> Debug for GCounter<A>

source§

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

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

impl<A: Ord> Default for GCounter<A>

source§

fn default() -> Self

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

impl<'de, A> Deserialize<'de> for GCounter<A>where 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<A: Hash + Ord> Hash for GCounter<A>

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<A: PartialEq + Ord> PartialEq<GCounter<A>> for GCounter<A>

source§

fn eq(&self, other: &GCounter<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<A: Ord> ResetRemove<A> for GCounter<A>

source§

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

Remove data that is strictly smaller than this clock
source§

impl<A> Serialize for GCounter<A>where 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<A: Eq + Ord> Eq for GCounter<A>

source§

impl<A: Ord> StructuralEq for GCounter<A>

source§

impl<A: Ord> StructuralPartialEq for GCounter<A>

Auto Trait Implementations§

§

impl<A> RefUnwindSafe for GCounter<A>where A: RefUnwindSafe,

§

impl<A> Send for GCounter<A>where A: Send,

§

impl<A> Sync for GCounter<A>where A: Sync,

§

impl<A> Unpin for GCounter<A>

§

impl<A> UnwindSafe for GCounter<A>where A: RefUnwindSafe,

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,