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 FloatArray(Vec<f32>),
31}
32
33impl PropertyValue {
35 pub fn boolean(b: bool) -> Self {
37 PropertyValue::Boolean(b)
38 }
39 pub fn integer(i: i64) -> Self {
41 PropertyValue::Integer(i)
42 }
43 pub fn float(f: f64) -> Self {
45 PropertyValue::Float(f)
46 }
47 pub fn string(s: impl Into<String>) -> Self {
49 PropertyValue::String(s.into())
50 }
51 pub fn array(arr: Vec<PropertyValue>) -> Self {
53 PropertyValue::Array(arr)
54 }
55 pub fn map(m: HashMap<String, PropertyValue>) -> Self {
57 PropertyValue::Map(m)
58 }
59 pub fn float_array(arr: Vec<f32>) -> Self {
61 PropertyValue::FloatArray(arr)
62 }
63}
64
65impl From<bool> for PropertyValue {
67 fn from(b: bool) -> Self {
68 PropertyValue::Boolean(b)
69 }
70}
71
72impl From<i64> for PropertyValue {
73 fn from(i: i64) -> Self {
74 PropertyValue::Integer(i)
75 }
76}
77
78impl From<i32> for PropertyValue {
79 fn from(i: i32) -> Self {
80 PropertyValue::Integer(i as i64)
81 }
82}
83
84impl From<f64> for PropertyValue {
85 fn from(f: f64) -> Self {
86 PropertyValue::Float(f)
87 }
88}
89
90impl From<f32> for PropertyValue {
91 fn from(f: f32) -> Self {
92 PropertyValue::Float(f as f64)
93 }
94}
95
96impl From<String> for PropertyValue {
97 fn from(s: String) -> Self {
98 PropertyValue::String(s)
99 }
100}
101
102impl From<&str> for PropertyValue {
103 fn from(s: &str) -> Self {
104 PropertyValue::String(s.to_string())
105 }
106}
107
108impl<T: Into<PropertyValue>> From<Vec<T>> for PropertyValue {
109 fn from(v: Vec<T>) -> Self {
110 PropertyValue::Array(v.into_iter().map(Into::into).collect())
111 }
112}
113
114impl From<HashMap<String, PropertyValue>> for PropertyValue {
115 fn from(m: HashMap<String, PropertyValue>) -> Self {
116 PropertyValue::Map(m)
117 }
118}
119
120pub type Properties = HashMap<String, PropertyValue>;
121
122#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize, Encode, Decode)]
123pub struct Label {
124 pub name: String,
125}
126
127impl Label {
128 pub fn new(name: impl Into<String>) -> Self {
129 Self { name: name.into() }
130 }
131}
132
133#[derive(Debug, Clone, Serialize, Deserialize, Encode, Decode)]
134pub struct RelationType {
135 pub name: String,
136}
137
138impl RelationType {
139 pub fn new(name: impl Into<String>) -> Self {
140 Self { name: name.into() }
141 }
142}