crdts_macro 7.3.0

CRDTs proc_macro
Documentation
  • Coverage
  • 0%
    0 out of 1 items documented0 out of 0 items with examples
  • Size
  • Source code size: 17.43 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 4.65 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 33s Average build duration of successful builds.
  • all releases: 33s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • JLerxky/crdts_macro
    2 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • JLerxky

crdts_macro

crates.io

Usage

Add the dependency

Add the crdts and crdts_macro dependency to Cargo.toml:

[dependencies]
crdts = "7.3"
crdts_macro = "7.3"

Custom CRDT struct

use crdts::{GCounter, Map, Orswot};
use crdts_macro::crdt;

#[crdt(u64)]
pub struct Data {
    a: Orswot<String, String>,
    b: Map<u64, Orswot<Vec<u8>, u64>, u64>,
    c: Orswot<Vec<u8>, u64>,
    d: GCounter<u64>,
}

Use this struct

#[test]
fn test() {
    use crdts::{CmRDT, CvRDT, Dot};
    let mut data1 = Data::default();
    let mut data2 = data1.clone();
    let actor = 1;
    let counter = 1;
    let dot = Dot::new(actor, counter);
    let op1 = data1.a.add(
        format!("{actor}-{counter}"),
        data1.a.read_ctx().derive_add_ctx(actor.to_string()),
    );

    let add_ctx = data1.b.read_ctx().derive_add_ctx(actor);
    let op2 = data1
        .b
        .update(actor, add_ctx, |v, a| v.add(vec![actor as u8; 20], a));

    let op3 = data1
        .c
        .add(vec![actor as u8; 20], data1.c.read_ctx().derive_add_ctx(actor));

    let op4 = data1.d.inc(actor);
    data1.apply(DataCrdtOp {
        dot,
        a_op: Some(op1),
        b_op: Some(op2),
        c_op: Some(op3),
        d_op: Some(op4),
    });
    println!("data1: {:#?}", data1);

    let actor = 2;
    let counter = 1;
    let dot = Dot::new(actor, counter);
    let op1 = data2.a.add(
        format!("{actor}-{counter}"),
        data2.a.read_ctx().derive_add_ctx(actor.to_string()),
    );

    let add_ctx = data2.b.read_ctx().derive_add_ctx(actor);
    let op2 = data2
        .b
        .update(actor, add_ctx, |v, a| v.add(vec![actor as u8; 20], a));

    let op3 = data2
        .c
        .add(vec![actor as u8; 20], data2.c.read_ctx().derive_add_ctx(actor));

    let op4 = data2.d.inc(actor);
    data2.apply(DataCrdtOp {
        dot,
        a_op: Some(op1),
        b_op: Some(op2),
        c_op: Some(op3),
        d_op: Some(op4),
    });
    println!("data2: {:#?}", data2);

    data1.merge(data2);
    println!("data3: {:#?}", data1);
}

Compatible crdts versions

Compatibility of crdts_macro versions:

crdts_macro crdts
7.3 7.3