1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use std::fmt::Debug;
use serde::{Deserialize, Serialize};
use crate::{CmRDT, Dot, VClock};
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct ReadCtx<V, A: Ord> {
pub add_clock: VClock<A>,
pub rm_clock: VClock<A>,
pub val: V,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct AddCtx<A: Ord> {
pub clock: VClock<A>,
pub dot: Dot<A>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RmCtx<A: Ord> {
pub clock: VClock<A>,
}
impl<V, A: Ord + Clone + Debug> ReadCtx<V, A> {
pub fn derive_add_ctx(self, actor: A) -> AddCtx<A> {
let mut clock = self.add_clock;
let dot = clock.inc(actor);
clock.apply(dot.clone());
AddCtx { clock, dot }
}
pub fn derive_rm_ctx(self) -> RmCtx<A> {
RmCtx {
clock: self.rm_clock,
}
}
pub fn split(self) -> (V, ReadCtx<(), A>) {
(
self.val,
ReadCtx {
add_clock: self.add_clock,
rm_clock: self.rm_clock,
val: (),
},
)
}
}