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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use std::fmt::{self, Display, Formatter};
use std::time::SystemTime;
use super::Type;
use crate::functions::AutogenFunction;
#[derive(PartialEq, Debug, Clone)]
pub enum WrappedDefault<'outer> {
AnyText(&'outer str),
Integer(i64),
Float(f32),
Double(f64),
UUID(String),
Boolean(bool),
Date(SystemTime),
Binary(&'outer [u8]),
Foreign(Box<Type>),
Custom(&'static str),
Array(Vec<Type>),
Function(AutogenFunction),
Null,
}
impl<'outer> Display for WrappedDefault<'outer> {
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
use self::WrappedDefault::*;
write!(
f,
"{}",
&match *self {
AnyText(ref val) => format!("{}", val),
Integer(ref val) => format!("{}", val),
Float(ref val) => format!("{}", val),
Double(ref val) => format!("{}", val),
UUID(ref val) => format!("{}", val),
Boolean(ref val) => format!("{}", val),
Date(ref val) => format!("{:?}", val),
Binary(ref val) => format!("{:?}", val),
Foreign(ref val) => format!("{:?}", val),
Custom(ref val) => format!("{}", val),
Array(ref val) => format!("{:?}", val),
Function(ref fun) => format!("{:?}", fun),
Null => format!("NULL"),
}
)
}
}
impl From<AutogenFunction> for WrappedDefault<'static> {
fn from(fun: AutogenFunction) -> Self {
WrappedDefault::Function(fun)
}
}
impl From<&'static str> for WrappedDefault<'static> {
fn from(s: &'static str) -> Self {
WrappedDefault::AnyText(s)
}
}
impl From<i64> for WrappedDefault<'static> {
fn from(s: i64) -> Self {
WrappedDefault::Integer(s)
}
}
impl From<f32> for WrappedDefault<'static> {
fn from(s: f32) -> Self {
WrappedDefault::Float(s)
}
}
impl From<f64> for WrappedDefault<'static> {
fn from(s: f64) -> Self {
WrappedDefault::Double(s)
}
}
impl From<bool> for WrappedDefault<'static> {
fn from(s: bool) -> Self {
WrappedDefault::Boolean(s)
}
}
impl From<SystemTime> for WrappedDefault<'static> {
fn from(s: SystemTime) -> Self {
WrappedDefault::Date(s)
}
}
pub fn null() -> WrappedDefault<'static> {
WrappedDefault::Null
}