Struct crdts::pncounter::PNCounter [−][src]
pub struct PNCounter<A: Ord> { /* 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());
Implementations
impl<A: Ord + Clone> 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 inc_many(&self, actor: A, steps: u64) -> Op<A>
[src]
Generate an Op to increment the counter by a number of steps.
pub fn dec_many(&self, actor: A, steps: u64) -> Op<A>
[src]
Generate an Op to decrement the counter by a number of steps.
pub fn read(&self) -> BigInt
[src]
Return the current value of this counter (P-N).
Trait Implementations
impl<A: Clone + Ord> Clone for PNCounter<A>
[src]
impl<A: Ord + Clone + Debug> 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
type Validation = <GCounter<A> as CmRDT>::Validation
The validation error returned by validate_op
.
fn validate_op(&self, op: &Self::Op) -> Result<(), Self::Validation>
[src]
fn apply(&mut self, op: Self::Op)
[src]
impl<A: Ord + Clone + Debug> CvRDT for PNCounter<A>
[src]
type Validation = <GCounter<A> as CvRDT>::Validation
The validation error returned by validate_merge
.
fn validate_merge(&self, other: &Self) -> Result<(), Self::Validation>
[src]
fn merge(&mut self, other: Self)
[src]
impl<A: Debug + Ord> Debug for PNCounter<A>
[src]
impl<A: Ord> Default for PNCounter<A>
[src]
impl<'de, A: Ord> Deserialize<'de> for PNCounter<A> where
A: Deserialize<'de>,
[src]
A: Deserialize<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl<A: Eq + Ord> Eq for PNCounter<A>
[src]
impl<A: Hash + Ord> Hash for PNCounter<A>
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<A: PartialEq + Ord> PartialEq<PNCounter<A>> for PNCounter<A>
[src]
impl<A: Ord> ResetRemove<A> for PNCounter<A>
[src]
fn reset_remove(&mut self, clock: &VClock<A>)
[src]
impl<A: Ord> Serialize for PNCounter<A> where
A: Serialize,
[src]
A: Serialize,
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<A: Ord> StructuralEq for PNCounter<A>
[src]
impl<A: Ord> StructuralPartialEq for PNCounter<A>
[src]
Auto Trait Implementations
impl<A> RefUnwindSafe for PNCounter<A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
impl<A> Send for PNCounter<A> where
A: Send,
A: Send,
impl<A> Sync for PNCounter<A> where
A: Sync,
A: Sync,
impl<A> Unpin for PNCounter<A>
impl<A> UnwindSafe for PNCounter<A> where
A: RefUnwindSafe,
A: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<A, T> Val<A> for T where
A: Ord,
T: Clone + Default + ResetRemove<A> + CmRDT,
[src]
A: Ord,
T: Clone + Default + ResetRemove<A> + CmRDT,