pub struct PNCounter<A: Ord> { /* private fields */ }
Expand description
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());
Implementations§
Trait Implementations§
source§impl<A: Ord + Clone + Debug> CmRDT for PNCounter<A>
impl<A: Ord + Clone + Debug> CmRDT for PNCounter<A>
§type Op = Op<A>
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
§type Validation = <GCounter<A> as CmRDT>::Validation
type Validation = <GCounter<A> as CmRDT>::Validation
The validation error returned by
validate_op
.source§fn validate_op(&self, op: &Self::Op) -> Result<(), Self::Validation>
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§impl<A: Ord + Clone + Debug> CvRDT for PNCounter<A>
impl<A: Ord + Clone + Debug> CvRDT for PNCounter<A>
§type Validation = <GCounter<A> as CvRDT>::Validation
type Validation = <GCounter<A> as CvRDT>::Validation
The validation error returned by
validate_merge
.source§fn validate_merge(&self, other: &Self) -> Result<(), Self::Validation>
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<'de, A> Deserialize<'de> for PNCounter<A>where
A: Deserialize<'de> + Ord,
impl<'de, A> Deserialize<'de> for PNCounter<A>where A: Deserialize<'de> + Ord,
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
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: PartialEq + Ord> PartialEq<PNCounter<A>> for PNCounter<A>
impl<A: PartialEq + Ord> PartialEq<PNCounter<A>> for PNCounter<A>
source§impl<A: Ord> ResetRemove<A> for PNCounter<A>
impl<A: Ord> ResetRemove<A> for PNCounter<A>
source§fn reset_remove(&mut self, clock: &VClock<A>)
fn reset_remove(&mut self, clock: &VClock<A>)
Remove data that is strictly smaller than this clock
impl<A: Eq + Ord> Eq for PNCounter<A>
impl<A: Ord> StructuralEq for PNCounter<A>
impl<A: Ord> StructuralPartialEq for PNCounter<A>
Auto Trait Implementations§
impl<A> RefUnwindSafe for PNCounter<A>where A: RefUnwindSafe,
impl<A> Send for PNCounter<A>where A: Send,
impl<A> Sync for PNCounter<A>where A: Sync,
impl<A> Unpin for PNCounter<A>
impl<A> UnwindSafe for PNCounter<A>where A: RefUnwindSafe,
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more