modality_mutation_plane/
types.rs1use modality_mutator_protocol::attrs::AttrVal;
2use uuid::Uuid;
3
4#[derive(Debug, PartialEq, Eq, Copy, Clone, PartialOrd, Ord, Hash)]
5pub struct ParticipantId(Uuid);
6#[derive(Debug, PartialEq, Eq, Copy, Clone, PartialOrd, Ord)]
7pub struct MutatorId(Uuid);
8#[derive(Debug, PartialEq, Eq, Copy, Clone, Hash)]
9pub struct MutationId(Uuid);
10
11#[derive(Debug, PartialEq, Eq, Clone)]
12pub struct TriggerCRDT(Vec<u8>);
13
14impl TriggerCRDT {
15 pub fn new(v: Vec<u8>) -> Self {
16 Self(v)
17 }
18}
19
20impl AsRef<[u8]> for TriggerCRDT {
21 fn as_ref(&self) -> &[u8] {
22 &self.0
23 }
24}
25
26impl<T> From<T> for TriggerCRDT
27where
28 T: Iterator<Item = u8>,
29{
30 fn from(t: T) -> Self {
31 Self(t.collect())
32 }
33}
34
35impl From<TriggerCRDT> for Vec<u8> {
36 fn from(v: TriggerCRDT) -> Self {
37 v.0
38 }
39}
40
41impl ParticipantId {
42 pub fn allocate() -> Self {
43 Self(Uuid::new_v4())
44 }
45}
46
47impl From<Uuid> for ParticipantId {
48 fn from(v: Uuid) -> Self {
49 Self(v)
50 }
51}
52impl From<ParticipantId> for Uuid {
53 fn from(v: ParticipantId) -> Self {
54 v.0
55 }
56}
57
58impl MutatorId {
59 pub fn allocate() -> Self {
60 Self(Uuid::new_v4())
61 }
62}
63
64impl From<Uuid> for MutatorId {
65 fn from(v: Uuid) -> Self {
66 Self(v)
67 }
68}
69impl From<MutatorId> for Uuid {
70 fn from(v: MutatorId) -> Self {
71 v.0
72 }
73}
74impl From<Uuid> for MutationId {
75 fn from(v: Uuid) -> Self {
76 Self(v)
77 }
78}
79impl From<MutationId> for Uuid {
80 fn from(v: MutationId) -> Self {
81 v.0
82 }
83}
84
85impl AsRef<Uuid> for ParticipantId {
86 fn as_ref(&self) -> &Uuid {
87 &self.0
88 }
89}
90impl AsRef<Uuid> for MutatorId {
91 fn as_ref(&self) -> &Uuid {
92 &self.0
93 }
94}
95impl AsRef<Uuid> for MutationId {
96 fn as_ref(&self) -> &Uuid {
97 &self.0
98 }
99}
100
101impl std::fmt::Display for ParticipantId {
102 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
103 self.0.fmt(f)
104 }
105}
106impl std::fmt::Display for MutatorId {
107 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
108 self.0.fmt(f)
109 }
110}
111impl std::fmt::Display for MutationId {
112 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113 self.0.fmt(f)
114 }
115}
116#[derive(Debug, PartialEq, Clone, minicbor::Encode, minicbor::Decode)]
117#[cbor(transparent)]
118pub struct AttrKvs(#[n(0)] pub Vec<AttrKv>);
119
120#[derive(Debug, PartialEq, Clone, minicbor::Encode, minicbor::Decode)]
121pub struct AttrKv {
122 #[n(0)]
123 pub key: String,
124 #[n(1)]
125 pub value: AttrVal,
126}