1use bincode::{Decode, Encode};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7pub type NodeId = String;
8pub type EdgeId = String;
9
10#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Encode, Decode)]
12pub enum PropertyValue {
13 Null,
15 Boolean(bool),
17 Integer(i64),
19 Float(f64),
21 String(String),
23 Array(Vec<PropertyValue>),
25 List(Vec<PropertyValue>),
27 Map(HashMap<String, PropertyValue>),
29}
30
31impl PropertyValue {
33 pub fn boolean(b: bool) -> Self {
35 PropertyValue::Boolean(b)
36 }
37 pub fn integer(i: i64) -> Self {
39 PropertyValue::Integer(i)
40 }
41 pub fn float(f: f64) -> Self {
43 PropertyValue::Float(f)
44 }
45 pub fn string(s: impl Into<String>) -> Self {
47 PropertyValue::String(s.into())
48 }
49 pub fn array(arr: Vec<PropertyValue>) -> Self {
51 PropertyValue::Array(arr)
52 }
53 pub fn map(m: HashMap<String, PropertyValue>) -> Self {
55 PropertyValue::Map(m)
56 }
57}
58
59impl From<bool> for PropertyValue {
61 fn from(b: bool) -> Self {
62 PropertyValue::Boolean(b)
63 }
64}
65
66impl From<i64> for PropertyValue {
67 fn from(i: i64) -> Self {
68 PropertyValue::Integer(i)
69 }
70}
71
72impl From<i32> for PropertyValue {
73 fn from(i: i32) -> Self {
74 PropertyValue::Integer(i as i64)
75 }
76}
77
78impl From<f64> for PropertyValue {
79 fn from(f: f64) -> Self {
80 PropertyValue::Float(f)
81 }
82}
83
84impl From<f32> for PropertyValue {
85 fn from(f: f32) -> Self {
86 PropertyValue::Float(f as f64)
87 }
88}
89
90impl From<String> for PropertyValue {
91 fn from(s: String) -> Self {
92 PropertyValue::String(s)
93 }
94}
95
96impl From<&str> for PropertyValue {
97 fn from(s: &str) -> Self {
98 PropertyValue::String(s.to_string())
99 }
100}
101
102impl<T: Into<PropertyValue>> From<Vec<T>> for PropertyValue {
103 fn from(v: Vec<T>) -> Self {
104 PropertyValue::Array(v.into_iter().map(Into::into).collect())
105 }
106}
107
108impl From<HashMap<String, PropertyValue>> for PropertyValue {
109 fn from(m: HashMap<String, PropertyValue>) -> Self {
110 PropertyValue::Map(m)
111 }
112}
113
114pub type Properties = HashMap<String, PropertyValue>;
115
116#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Encode, Decode)]
117pub struct Label {
118 pub name: String,
119}
120
121impl Label {
122 pub fn new(name: impl Into<String>) -> Self {
123 Self { name: name.into() }
124 }
125}
126
127#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
128pub struct RelationType {
129 pub name: String,
130}
131
132impl RelationType {
133 pub fn new(name: impl Into<String>) -> Self {
134 Self { name: name.into() }
135 }
136}