1use std::{
5 fmt,
6 fmt::{Display, Formatter},
7 num::ParseIntError,
8 str::FromStr,
9 time::Duration,
10};
11
12use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
13
14#[repr(transparent)]
15#[derive(Debug, Copy, Clone, PartialOrd, PartialEq, Ord, Eq, Hash)]
16pub struct CommitVersion(pub u64);
17
18impl FromStr for CommitVersion {
19 type Err = ParseIntError;
20
21 fn from_str(s: &str) -> Result<Self, Self::Err> {
22 Ok(CommitVersion(u64::from_str(s)?))
23 }
24}
25
26impl Display for CommitVersion {
27 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
28 Display::fmt(&self.0, f)
29 }
30}
31
32impl PartialEq<i32> for CommitVersion {
33 fn eq(&self, other: &i32) -> bool {
34 self.0 == *other as u64
35 }
36}
37
38impl PartialEq<CommitVersion> for i32 {
39 fn eq(&self, other: &CommitVersion) -> bool {
40 *self as u64 == other.0
41 }
42}
43
44impl PartialEq<u64> for CommitVersion {
45 fn eq(&self, other: &u64) -> bool {
46 self.0.eq(other)
47 }
48}
49
50impl From<CommitVersion> for u64 {
51 fn from(value: CommitVersion) -> Self {
52 value.0
53 }
54}
55
56impl From<i32> for CommitVersion {
57 fn from(value: i32) -> Self {
58 Self(value as u64)
59 }
60}
61
62impl From<u64> for CommitVersion {
63 fn from(value: u64) -> Self {
64 Self(value)
65 }
66}
67
68impl Serialize for CommitVersion {
69 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
70 where
71 S: Serializer,
72 {
73 serializer.serialize_u64(self.0)
74 }
75}
76
77impl<'de> Deserialize<'de> for CommitVersion {
78 fn deserialize<D>(deserializer: D) -> Result<CommitVersion, D::Error>
79 where
80 D: Deserializer<'de>,
81 {
82 struct U64Visitor;
83
84 impl Visitor<'_> for U64Visitor {
85 type Value = CommitVersion;
86
87 fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
88 formatter.write_str("an unsigned 64-bit number")
89 }
90
91 fn visit_u64<E>(self, value: u64) -> Result<Self::Value, E> {
92 Ok(CommitVersion(value))
93 }
94 }
95
96 deserializer.deserialize_u64(U64Visitor)
97 }
98}
99
100#[derive(Debug, Clone, Copy, PartialEq, Serialize, Deserialize)]
101pub enum JoinType {
102 Inner,
103 Left,
104}
105
106impl Default for JoinType {
107 fn default() -> Self {
108 JoinType::Left
109 }
110}
111
112#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
113pub enum IndexType {
114 Index,
115 Unique,
116 Primary,
117}
118
119impl Default for IndexType {
120 fn default() -> Self {
121 IndexType::Index
122 }
123}
124
125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
126pub enum WindowType {
127 Time(WindowTimeMode),
128 Count,
129}
130
131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
132pub enum WindowTimeMode {
133 Processing,
134 EventTime(String),
135}
136
137impl Default for WindowType {
138 fn default() -> Self {
139 WindowType::Time(WindowTimeMode::Processing)
140 }
141}
142
143impl Default for WindowTimeMode {
144 fn default() -> Self {
145 WindowTimeMode::Processing
146 }
147}
148
149#[derive(Debug, Clone, Serialize, Deserialize)]
150pub enum WindowSize {
151 Duration(Duration),
152 Count(u64),
153}
154
155#[derive(Debug, Clone, Serialize, Deserialize)]
156pub enum WindowSlide {
157 Duration(Duration),
158 Count(u64),
159 Rolling,
160}