1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
use chrono::{NaiveDate, NaiveDateTime, NaiveTime};
#[derive(Copy, Clone, Debug, PartialEq)]
pub enum Value<'a> {
Null,
Ident(&'a str),
Column {
table_name: Option<&'a str>,
column_name: &'a str,
},
String(&'a str),
I64(i64),
I32(i32),
I16(i16),
Bool(bool),
F64(f64),
F32(f32),
Binary(&'a [u8]),
NaiveTime(NaiveTime),
NaiveDate(NaiveDate),
NaiveDateTime(NaiveDateTime),
}
macro_rules! impl_from_with_lft {
($variant:ident, $T:ty) => {
impl<'a> From<&'a $T> for Value<'a> {
fn from(value: &'a $T) -> Self {
Value::$variant(value)
}
}
};
}
impl_from_with_lft!(Binary, [u8]);
impl_from_with_lft!(String, str);
macro_rules! impl_from {
($variant:ident, $T:ty) => {
impl From<$T> for Value<'static> {
fn from(value: $T) -> Self {
Value::$variant(value)
}
}
};
}
impl_from!(I64, i64);
impl_from!(I32, i32);
impl_from!(I16, i16);
impl_from!(Bool, bool);
impl_from!(F64, f64);
impl_from!(F32, f32);
impl_from!(NaiveDate, chrono::NaiveDate);
impl_from!(NaiveTime, chrono::NaiveTime);
impl_from!(NaiveDateTime, chrono::NaiveDateTime);
impl<'a, T> From<&'a T> for Value<'static>
where
Self: From<T>,
T: Copy,
{
fn from(reference: &'a T) -> Self {
Self::from(*reference)
}
}