crdt_graph/types/
simple.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}
12
13impl TwoPTwoPId<Uuid> for AddVertex {
14 fn id(&self) -> &Uuid {
15 &self.id
16 }
17}
18
19impl TwoPTwoPAddVertex<Uuid> for AddVertex {}
20
21#[derive(Clone, Debug, PartialEq, Eq, Hash)]
23pub struct AddEdge {
24 pub id: Uuid,
25 pub source: Uuid,
26 pub target: Uuid,
27}
28
29impl TwoPTwoPId<Uuid> for AddEdge {
30 fn id(&self) -> &Uuid {
31 &self.id
32 }
33}
34
35impl TwoPTwoPAddEdge<Uuid> for AddEdge {
36 fn source(&self) -> &Uuid {
37 &self.source
38 }
39 fn target(&self) -> &Uuid {
40 &self.target
41 }
42}
43
44pub type Graph = TwoPTwoPGraph<AddVertex, RemoveVertex, AddEdge, RemoveEdge, Uuid>;
46
47pub type Operation = UpdateOperation<AddVertex, RemoveVertex, AddEdge, RemoveEdge>;
49
50impl From<AddVertex> for Operation {
51 fn from(v: AddVertex) -> Self {
52 UpdateOperation::AddVertex(v)
53 }
54}
55
56impl From<RemoveVertex> for Operation {
57 fn from(v: RemoveVertex) -> Self {
58 UpdateOperation::RemoveVertex(v)
59 }
60}
61
62impl From<AddEdge> for Operation {
63 fn from(e: AddEdge) -> Self {
64 UpdateOperation::AddEdge(e)
65 }
66}
67
68impl From<RemoveEdge> for Operation {
69 fn from(e: RemoveEdge) -> Self {
70 UpdateOperation::RemoveEdge(e)
71 }
72}