1use std::fmt::{self, Display, Formatter};
2
3use serde::{Deserialize, Serialize};
4
5pub mod entities;
6pub mod input;
7pub mod storage;
8pub mod utils;
9
10#[derive(Clone, Copy, Hash, Eq, PartialEq, PartialOrd, Debug, Default, Serialize, Deserialize)]
12pub enum Direction {
13 OUT,
14 IN,
15 #[default]
16 BOTH,
17}
18
19#[derive(Copy, Clone, PartialEq, Eq, Debug, Default, Serialize, Deserialize)]
20pub enum PropType {
21 #[default]
22 Empty,
23 Str,
24 U8,
25 U16,
26 I32,
27 I64,
28 U32,
29 U64,
30 F32,
31 F64,
32 Bool,
33 List,
34 Map,
35 NDTime,
36 Graph,
37 PersistentGraph,
38 Document,
39 DTime,
40}
41
42impl Display for PropType {
43 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
44 let type_str = match self {
45 PropType::Empty => "Empty",
46 PropType::Str => "Str",
47 PropType::U8 => "U8",
48 PropType::U16 => "U16",
49 PropType::I32 => "I32",
50 PropType::I64 => "I64",
51 PropType::U32 => "U32",
52 PropType::U64 => "U64",
53 PropType::F32 => "F32",
54 PropType::F64 => "F64",
55 PropType::Bool => "Bool",
56 PropType::List => "List",
57 PropType::Map => "Map",
58 PropType::NDTime => "NDTime",
59 PropType::Graph => "Graph",
60 PropType::PersistentGraph => "PersistentGraph",
61 PropType::Document => "Document",
62 PropType::DTime => "DTime",
63 };
64
65 write!(f, "{}", type_str)
66 }
67}
68
69impl PropType {
70 pub fn is_numeric(&self) -> bool {
71 matches!(
72 self,
73 PropType::U8
74 | PropType::U16
75 | PropType::U32
76 | PropType::U64
77 | PropType::I32
78 | PropType::I64
79 | PropType::F32
80 | PropType::F64
81 )
82 }
83
84 pub fn is_str(&self) -> bool {
85 matches!(self, PropType::Str)
86 }
87
88 pub fn is_bool(&self) -> bool {
89 matches!(self, PropType::Bool)
90 }
91
92 pub fn is_date(&self) -> bool {
93 matches!(self, PropType::DTime | PropType::NDTime)
94 }
95
96 pub fn has_add(&self) -> bool {
97 self.is_numeric() || self.is_str()
98 }
99
100 pub fn has_divide(&self) -> bool {
101 self.is_numeric()
102 }
103
104 pub fn has_cmp(&self) -> bool {
105 self.is_bool() || self.is_numeric() || self.is_str() || self.is_date()
106 }
107}
108
109#[cfg(feature = "storage")]
110use polars_arrow::datatypes::ArrowDataType as DataType;
111
112#[cfg(feature = "storage")]
113impl From<&DataType> for PropType {
114 fn from(value: &DataType) -> Self {
115 match value {
116 DataType::Utf8 => PropType::Str,
117 DataType::LargeUtf8 => PropType::Str,
118 DataType::UInt8 => PropType::U8,
119 DataType::UInt16 => PropType::U16,
120 DataType::Int32 => PropType::I32,
121 DataType::Int64 => PropType::I64,
122 DataType::UInt32 => PropType::U32,
123 DataType::UInt64 => PropType::U64,
124 DataType::Float32 => PropType::F32,
125 DataType::Float64 => PropType::F64,
126 DataType::Boolean => PropType::Bool,
127
128 _ => PropType::Empty,
129 }
130 }
131}