Skip to content

Commit a65ea72

Browse files
committed
Add geometric, json, network, search, and uuid types with display implementations
1 parent 6da750f commit a65ea72

File tree

6 files changed

+395
-1
lines changed

6 files changed

+395
-1
lines changed

src/types/geometric.rs

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
// src/types/geometry.rs
2+
3+
// Geometry types
4+
#[derive(Debug, PartialEq)]
5+
pub enum Geometry {
6+
Point,
7+
LineString,
8+
Polygon,
9+
MultiPoint,
10+
MultiLineString,
11+
MultiPolygon,
12+
GeometryCollection,
13+
}
14+
15+
// impl PartialEq for Geometry
16+
impl PartialEq for Geometry {
17+
fn eq(&self, other: &Self) -> bool {
18+
match self {
19+
Geometry::Point => {
20+
if let Geometry::Point = other {
21+
true
22+
} else {
23+
false
24+
}
25+
},
26+
Geometry::LineString => {
27+
if let Geometry::LineString = other {
28+
true
29+
} else {
30+
false
31+
}
32+
},
33+
Geometry::Polygon => {
34+
if let Geometry::Polygon = other {
35+
true
36+
} else {
37+
false
38+
}
39+
},
40+
Geometry::MultiPoint => {
41+
if let Geometry::MultiPoint = other {
42+
true
43+
} else {
44+
false
45+
}
46+
},
47+
Geometry::MultiLineString => {
48+
if let Geometry::MultiLineString = other {
49+
true
50+
} else {
51+
false
52+
}
53+
},
54+
Geometry::MultiPolygon => {
55+
if let Geometry::MultiPolygon = other {
56+
true
57+
} else {
58+
false
59+
}
60+
},
61+
Geometry::GeometryCollection => {
62+
if let Geometry::GeometryCollection = other {
63+
true
64+
} else {
65+
false
66+
}
67+
},
68+
}
69+
}
70+
}
71+
72+
// impl Geometry
73+
impl Geometry {
74+
pub fn to_string(&self) -> String {
75+
self.to_string()
76+
}
77+
}
78+
79+
// impl Display for Geometry
80+
impl std::fmt::Display for Geometry {
81+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
82+
match *self {
83+
Geometry::Point => write!(f, "POINT"),
84+
Geometry::LineString => write!(f, "LINESTRING"),
85+
Geometry::Polygon => write!(f, "POLYGON"),
86+
Geometry::MultiPoint => write!(f, "MULTIPOINT"),
87+
Geometry::MultiLineString => write!(f, "MULTILINESTRING"),
88+
Geometry::MultiPolygon => write!(f, "MULTIPOLYGON"),
89+
Geometry::GeometryCollection => write!(f, "GEOMETRYCOLLECTION"),
90+
}
91+
}
92+
}
93+
94+
// impl Geometry
95+
impl Geometry {
96+
pub fn to_string(&self) -> String {
97+
self.to_string()
98+
}
99+
}
100+
101+
// impl Display for Geometry
102+
impl std::fmt::Display for Geometry {
103+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
104+
match *self {
105+
Geometry::Point => write!(f, "POINT"),
106+
Geometry::LineString => write!(f, "LINESTRING"),
107+
Geometry::Polygon => write!(f, "POLYGON"),
108+
Geometry::MultiPoint => write!(f, "MULTIPOINT"),
109+
Geometry::MultiLineString => write!(f, "MULTILINESTRING"),
110+
Geometry::MultiPolygon => write!(f, "MULTIPOLYGON"),
111+
Geometry::GeometryCollection => write!(f, "GEOMETRYCOLLECTION"),
112+
}
113+
}
114+
}

src/types/json.rs

+106
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
// src/types/json.rs
2+
3+
// JSON types
4+
#[derive(Debug, PartialEq)]
5+
pub enum Json {
6+
Json,
7+
Jsonb,
8+
}
9+
10+
// Array types
11+
#[derive(Debug, PartialEq)]
12+
pub enum Array {
13+
Array,
14+
}
15+
16+
// impl PartialEq for Json
17+
impl PartialEq for Json {
18+
fn eq(&self, other: &Self) -> bool {
19+
match self {
20+
Json::Json => {
21+
if let Json::Json = other {
22+
true
23+
} else {
24+
false
25+
}
26+
},
27+
Json::Jsonb => {
28+
if let Json::Jsonb = other {
29+
true
30+
} else {
31+
false
32+
}
33+
},
34+
}
35+
}
36+
}
37+
38+
// impl Json
39+
impl Json {
40+
pub fn to_string(&self) -> String {
41+
self.to_string()
42+
}
43+
}
44+
45+
// impl Display for Json
46+
impl std::fmt::Display for Json {
47+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
48+
match *self {
49+
Json::Json => write!(f, "JSON"),
50+
Json::Jsonb => write!(f, "JSONB"),
51+
}
52+
}
53+
}
54+
55+
// impl PartialEq for Array
56+
impl PartialEq for Array {
57+
fn eq(&self, other: &Self) -> bool {
58+
match self {
59+
Array::Array => {
60+
if let Array::Array = other {
61+
true
62+
} else {
63+
false
64+
}
65+
},
66+
}
67+
}
68+
}
69+
70+
// impl Array
71+
impl Array {
72+
pub fn to_string(&self) -> String {
73+
self.to_string()
74+
}
75+
}
76+
77+
// impl Display for Array
78+
impl std::fmt::Display for Array {
79+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
80+
match *self {
81+
Array::Array => write!(f, "ARRAY"),
82+
}
83+
}
84+
}
85+
86+
// impl PartialEq for Json
87+
impl PartialEq for Json {
88+
fn eq(&self, other: &Self) -> bool {
89+
match self {
90+
Json::Json => {
91+
if let Json::Json = other {
92+
true
93+
} else {
94+
false
95+
}
96+
},
97+
Json::Jsonb => {
98+
if let Json::Jsonb = other {
99+
true
100+
} else {
101+
false
102+
}
103+
},
104+
}
105+
}
106+
}

src/types/mod.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
pub mod date;
22
pub mod enumerated;
33
pub mod numeric;
4-
pub mod character;
4+
pub mod character;
5+
pub mod geometric;
6+
pub mod network;
7+
pub mod search;
8+
pub mod uuid;
9+
pub mod json;

src/types/network.rs

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
// src/types/network.rs
2+
3+
// Network types
4+
#[derive(Debug, PartialEq)]
5+
pub enum Network {
6+
Cidr,
7+
Inet,
8+
MacAddr,
9+
MacAddr8,
10+
}
11+
12+
// impl PartialEq for Network
13+
impl PartialEq for Network {
14+
fn eq(&self, other: &Self) -> bool {
15+
match self {
16+
Network::Cidr => {
17+
if let Network::Cidr = other {
18+
true
19+
} else {
20+
false
21+
}
22+
},
23+
Network::Inet => {
24+
if let Network::Inet = other {
25+
true
26+
} else {
27+
false
28+
}
29+
},
30+
Network::MacAddr => {
31+
if let Network::MacAddr = other {
32+
true
33+
} else {
34+
false
35+
}
36+
},
37+
Network::MacAddr8 => {
38+
if let Network::MacAddr8 = other {
39+
true
40+
} else {
41+
false
42+
}
43+
},
44+
}
45+
}
46+
}
47+
48+
// impl Network
49+
impl Network {
50+
pub fn to_string(&self) -> String {
51+
self.to_string()
52+
}
53+
}
54+
55+
// impl Display for Network
56+
impl std::fmt::Display for Network {
57+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
58+
match *self {
59+
Network::Cidr => write!(f, "CIDR"),
60+
Network::Inet => write!(f, "INET"),
61+
Network::MacAddr => write!(f, "MACADDR"),
62+
Network::MacAddr8 => write!(f, "MACADDR8"),
63+
}
64+
}
65+
}
66+
67+
// impl Network
68+
impl Network {
69+
pub fn to_string(&self) -> String {
70+
self.to_string()
71+
}
72+
}
73+
74+
// impl Display for Network
75+
impl std::fmt::Display for Network {
76+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
77+
match *self {
78+
Network::Cidr => write!(f, "CIDR"),
79+
Network::Inet => write!(f, "INET"),
80+
Network::MacAddr => write!(f, "MACADDR"),
81+
Network::MacAddr8 => write!(f, "MACADDR8"),
82+
}
83+
}
84+
}

src/types/search.rs

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// src/types/search.rs
2+
3+
// Search types
4+
#[derive(Debug, PartialEq)]
5+
pub enum Search {
6+
TsVector,
7+
TsQuery,
8+
}
9+
10+
// impl PartialEq for Search
11+
impl PartialEq for Search {
12+
fn eq(&self, other: &Self) -> bool {
13+
match self {
14+
Search::TsVector => {
15+
if let Search::TsVector = other {
16+
true
17+
} else {
18+
false
19+
}
20+
},
21+
Search::TsQuery => {
22+
if let Search::TsQuery = other {
23+
true
24+
} else {
25+
false
26+
}
27+
},
28+
}
29+
}
30+
}
31+
32+
// impl Search
33+
impl Search {
34+
pub fn to_string(&self) -> String {
35+
self.to_string()
36+
}
37+
}
38+
39+
// impl Display for Search
40+
impl std::fmt::Display for Search {
41+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
42+
match *self {
43+
Search::TsVector => write!(f, "TSVECTOR"),
44+
Search::TsQuery => write!(f, "TSQUERY"),
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)