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