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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
use modality_mutator_protocol::attrs::AttrVal;
use uuid::Uuid;

#[derive(Debug, PartialEq, Eq, Copy, Clone, PartialOrd, Ord, Hash)]
pub struct ParticipantId(Uuid);
#[derive(Debug, PartialEq, Eq, Copy, Clone, PartialOrd, Ord)]
pub struct MutatorId(Uuid);
#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
pub struct MutationId(Uuid);

#[derive(Debug, PartialEq, Eq, Clone)]
pub struct TriggerCRDT(Vec<u8>);

impl TriggerCRDT {
    pub fn new(v: Vec<u8>) -> Self {
        Self(v)
    }
}

impl AsRef<[u8]> for TriggerCRDT {
    fn as_ref(&self) -> &[u8] {
        &self.0
    }
}

impl<T> From<T> for TriggerCRDT
where
    T: Iterator<Item = u8>,
{
    fn from(t: T) -> Self {
        Self(t.collect())
    }
}

impl From<TriggerCRDT> for Vec<u8> {
    fn from(v: TriggerCRDT) -> Self {
        v.0
    }
}

impl ParticipantId {
    pub fn allocate() -> Self {
        Self(Uuid::new_v4())
    }
}

impl From<Uuid> for ParticipantId {
    fn from(v: Uuid) -> Self {
        Self(v)
    }
}
impl From<ParticipantId> for Uuid {
    fn from(v: ParticipantId) -> Self {
        v.0
    }
}

impl MutatorId {
    pub fn allocate() -> Self {
        Self(Uuid::new_v4())
    }
}

impl From<Uuid> for MutatorId {
    fn from(v: Uuid) -> Self {
        Self(v)
    }
}
impl From<MutatorId> for Uuid {
    fn from(v: MutatorId) -> Self {
        v.0
    }
}
impl From<Uuid> for MutationId {
    fn from(v: Uuid) -> Self {
        Self(v)
    }
}
impl From<MutationId> for Uuid {
    fn from(v: MutationId) -> Self {
        v.0
    }
}

impl AsRef<Uuid> for ParticipantId {
    fn as_ref(&self) -> &Uuid {
        &self.0
    }
}
impl AsRef<Uuid> for MutatorId {
    fn as_ref(&self) -> &Uuid {
        &self.0
    }
}
impl AsRef<Uuid> for MutationId {
    fn as_ref(&self) -> &Uuid {
        &self.0
    }
}

impl std::fmt::Display for ParticipantId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.0.fmt(f)
    }
}
impl std::fmt::Display for MutatorId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.0.fmt(f)
    }
}
impl std::fmt::Display for MutationId {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        self.0.fmt(f)
    }
}
#[derive(Debug, PartialEq, Clone, minicbor::Encode, minicbor::Decode)]
#[cbor(transparent)]
pub struct AttrKvs(#[n(0)] pub Vec<AttrKv>);

#[derive(Debug, PartialEq, Clone, minicbor::Encode, minicbor::Decode)]
pub struct AttrKv {
    #[n(0)]
    pub key: String,
    #[n(1)]
    pub value: AttrVal,
}