[][src]Struct crdts::pncounter::PNCounter

pub struct PNCounter<A: Actor> { /* fields omitted */ }

PNCounter allows the counter to be both incremented and decremented by representing the increments (P) and the decrements (N) in separate internal G-Counters.

Merge is implemented by merging the internal P and N counters. The value of the counter is P minus N.

Examples

use crdts::{PNCounter, CmRDT};

let mut a = PNCounter::new();
a.apply(a.inc("A"));
a.apply(a.inc("A"));
a.apply(a.dec("A"));
a.apply(a.inc("A"));

assert_eq!(a.read(), 2.into());

Methods

impl<A: Actor> PNCounter<A>[src]

pub fn new() -> Self[src]

Produce a new PNCounter.

pub fn inc(&self, actor: A) -> Op<A>[src]

Generate an Op to increment the counter.

pub fn dec(&self, actor: A) -> Op<A>[src]

Generate an Op to increment the counter.

pub fn read(&self) -> BigInt[src]

Return the current value of this counter (P-N).

Trait Implementations

impl<A: Actor> CvRDT for PNCounter<A>[src]

impl<A: Actor> CmRDT for PNCounter<A>[src]

type Op = Op<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

impl<A: Actor> Causal<A> for PNCounter<A>[src]

impl<A: PartialEq + Actor> PartialEq<PNCounter<A>> for PNCounter<A>[src]

impl<A: Actor> Default for PNCounter<A>[src]

impl<A: Clone + Actor> Clone for PNCounter<A>[src]

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl<A: Eq + Actor> Eq for PNCounter<A>[src]

impl<A: Hash + Actor> Hash for PNCounter<A>[src]

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

Feeds a slice of this type into the given [Hasher]. Read more

impl<A: Debug + Actor> Debug for PNCounter<A>[src]

impl<A: Actor> Serialize for PNCounter<A> where
    A: Serialize
[src]

impl<'de, A: Actor> Deserialize<'de> for PNCounter<A> where
    A: Deserialize<'de>, 
[src]

Auto Trait Implementations

impl<A> Sync for PNCounter<A> where
    A: Sync

impl<A> Send for PNCounter<A> where
    A: Send

impl<A> Unpin for PNCounter<A> where
    A: Unpin

impl<A> RefUnwindSafe for PNCounter<A> where
    A: RefUnwindSafe

impl<A> UnwindSafe for PNCounter<A> where
    A: RefUnwindSafe + UnwindSafe

Blanket Implementations

impl<T> Val for T where
    T: PartialEq<T> + Clone + Debug
[src]

impl<T> Val for T where
    T: Clone + Debug
[src]

impl<T> Member for T where
    T: Eq + Clone + Hash + Debug
[src]

impl<A, T> Val<A> for T where
    A: Actor,
    T: Debug + Default + Clone + Causal<A> + CmRDT + CvRDT
[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> From<T> for T[src]

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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]