pub struct PNCounter { /* private fields */ }Expand description
A positive-negative counter (PN-Counter).
Supports both increment and decrement operations by maintaining two
internal G-Counters: one for increments and one for decrements.
The value is increments - decrements.
§Example
use crdt_kit::prelude::*;
let mut c1 = PNCounter::new("node-1");
c1.increment();
c1.increment();
c1.decrement();
assert_eq!(c1.value(), 1);
let mut c2 = PNCounter::new("node-2");
c2.decrement();
c1.merge(&c2);
assert_eq!(c1.value(), 0);Implementations§
Trait Implementations§
Source§impl DeltaCrdt for PNCounter
impl DeltaCrdt for PNCounter
Source§type Delta = PNCounterDelta
type Delta = PNCounterDelta
The type of delta produced by this CRDT.
Source§fn delta(&self, other: &Self) -> PNCounterDelta
fn delta(&self, other: &Self) -> PNCounterDelta
Source§fn apply_delta(&mut self, delta: &PNCounterDelta)
fn apply_delta(&mut self, delta: &PNCounterDelta)
Apply a delta to this replica’s state. Read more
impl Eq for PNCounter
impl StructuralPartialEq for PNCounter
Auto Trait Implementations§
impl Freeze for PNCounter
impl RefUnwindSafe for PNCounter
impl Send for PNCounter
impl Sync for PNCounter
impl Unpin for PNCounter
impl UnwindSafe for PNCounter
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