clickhouse_rs_async/types/
enums.rs

1use std::{
2    fmt,
3    hash::{Hash, Hasher},
4};
5
6// TODO Using strings as a keys
7#[derive(Clone, Copy, Default)]
8pub struct Enum8(pub(crate) i8);
9
10#[derive(Clone, Copy, Default)]
11pub struct Enum16(pub(crate) i16);
12
13impl PartialEq for Enum16 {
14    fn eq(&self, other: &Self) -> bool {
15        self.0 == other.0
16    }
17}
18
19impl fmt::Display for Enum16 {
20    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
21        write!(f, "Enum({})", self.0)
22    }
23}
24
25impl fmt::Debug for Enum16 {
26    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
27        write!(f, "Enum({})", self.0)
28    }
29}
30
31impl Enum16 {
32    pub fn of(source: i16) -> Self {
33        Self(source)
34    }
35    #[inline(always)]
36    pub fn internal(self) -> i16 {
37        self.0
38    }
39}
40
41impl Hash for Enum16 {
42    fn hash<H: Hasher>(&self, state: &mut H) {
43        self.0.hash(state);
44    }
45}
46
47impl PartialEq for Enum8 {
48    fn eq(&self, other: &Self) -> bool {
49        self.0 == other.0
50    }
51}
52
53impl Hash for Enum8 {
54    fn hash<H: Hasher>(&self, state: &mut H) {
55        self.0.hash(state);
56    }
57}
58
59impl fmt::Display for Enum8 {
60    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
61        write!(f, "Enum8({})", self.0)
62    }
63}
64
65impl fmt::Debug for Enum8 {
66    fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
67        write!(f, "Enum8({})", self.0)
68    }
69}
70
71impl Enum8 {
72    pub fn of(source: i8) -> Self {
73        Self(source)
74    }
75    #[inline(always)]
76    pub fn internal(self) -> i8 {
77        self.0
78    }
79}