1use serde::{Deserialize, Serialize};
3use std::collections::HashMap;
4
5pub type NodeId = u128;
6pub type EdgeId = u128;
7
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Node {
10 pub id: NodeId,
11 pub label: String,
12 pub properties: HashMap<String, serde_json::Value>,
13}
14
15#[derive(Debug, Clone, Serialize, Deserialize)]
16pub struct Edge {
17 pub id: EdgeId,
18 pub from: NodeId,
19 pub to: NodeId,
20 pub label: String,
21 pub properties: HashMap<String, serde_json::Value>,
22}
23
24impl Node {
25 #[inline]
26 #[must_use]
27 pub fn new(id: NodeId, label: String) -> Self {
28 Self {
29 id,
30 label,
31 properties: HashMap::new(),
32 }
33 }
34
35 #[inline]
36 #[must_use]
37 pub fn with_property(mut self, key: String, value: serde_json::Value) -> Self {
38 self.properties.insert(key, value);
39 self
40 }
41}
42
43impl Edge {
44 #[inline]
45 #[must_use]
46 pub fn new(id: EdgeId, from: NodeId, to: NodeId, label: String) -> Self {
47 Self {
48 id,
49 from,
50 to,
51 label,
52 properties: HashMap::new(),
53 }
54 }
55
56 #[inline]
57 #[must_use]
58 pub fn with_property(mut self, key: String, value: serde_json::Value) -> Self {
59 self.properties.insert(key, value);
60 self
61 }
62}
63