crdt_graph/types/
string.rs1use crate::graph::{
2 TwoPTwoPAddEdge, TwoPTwoPAddVertex, TwoPTwoPGraph, TwoPTwoPId, UpdateOperation,
3};
4use super::{RemoveEdge, RemoveVertex};
5use uuid::Uuid;
6
7#[derive(Clone, Debug, PartialEq, Eq, Hash)]
9pub struct AddVertex {
10 pub id: Uuid,
11 pub data: Option<String>,
12}
13
14impl TwoPTwoPId<Uuid> for AddVertex {
15 fn id(&self) -> &Uuid {
16 &self.id
17 }
18}
19
20impl TwoPTwoPAddVertex<Uuid> for AddVertex {}
21
22#[derive(Clone, Debug, PartialEq, Eq, Hash)]
24pub struct AddEdge {
25 pub id: Uuid,
26 pub source: Uuid,
27 pub target: Uuid,
28 pub data: Option<String>,
29}
30
31impl TwoPTwoPId<Uuid> for AddEdge {
32 fn id(&self) -> &Uuid {
33 &self.id
34 }
35}
36
37impl TwoPTwoPAddEdge<Uuid> for AddEdge {
38 fn source(&self) -> &Uuid {
39 &self.source
40 }
41 fn target(&self) -> &Uuid {
42 &self.target
43 }
44}
45
46pub type Graph = TwoPTwoPGraph<AddVertex, RemoveVertex, AddEdge, RemoveEdge, Uuid>;
48
49pub type Operation = UpdateOperation<AddVertex, RemoveVertex, AddEdge, RemoveEdge>;
51
52impl From<AddVertex> for Operation {
53 fn from(v: AddVertex) -> Self {
54 UpdateOperation::AddVertex(v)
55 }
56}
57
58impl From<RemoveVertex> for Operation {
59 fn from(v: RemoveVertex) -> Self {
60 UpdateOperation::RemoveVertex(v)
61 }
62}
63
64impl From<AddEdge> for Operation {
65 fn from(e: AddEdge) -> Self {
66 UpdateOperation::AddEdge(e)
67 }
68}
69
70impl From<RemoveEdge> for Operation {
71 fn from(e: RemoveEdge) -> Self {
72 UpdateOperation::RemoveEdge(e)
73 }
74}