1#[derive(Clone, Debug, PartialEq, serde::Serialize)]
3pub enum Value {
4 Null,
6 Integer(i64),
8 Float(f64),
10 Text(String),
12 BlobBase64(String),
14}
15
16impl Value {
17 pub fn null() -> Self {
19 Self::Null
20 }
21
22 pub fn integer(value: i64) -> Self {
24 Self::Integer(value)
25 }
26
27 pub fn float(value: f64) -> Self {
29 Self::Float(value)
30 }
31
32 pub fn text(value: impl Into<String>) -> Self {
34 Self::Text(value.into())
35 }
36
37 pub fn blob_base64(value: impl Into<String>) -> Self {
39 Self::BlobBase64(value.into())
40 }
41}
42
43impl From<String> for Value {
44 fn from(value: String) -> Self {
45 Self::Text(value)
46 }
47}
48
49impl From<&str> for Value {
50 fn from(value: &str) -> Self {
51 Self::Text(value.to_owned())
52 }
53}
54
55impl From<i64> for Value {
56 fn from(value: i64) -> Self {
57 Self::Integer(value)
58 }
59}
60
61impl From<i32> for Value {
62 fn from(value: i32) -> Self {
63 Self::Integer(value.into())
64 }
65}
66
67impl From<f64> for Value {
68 fn from(value: f64) -> Self {
69 Self::Float(value)
70 }
71}
72
73#[cfg(test)]
74mod tests {
75 use crate::Value;
76
77 #[test]
78 fn helper_constructors() {
79 assert_eq!(Value::null(), Value::Null);
80 assert_eq!(Value::integer(7), Value::Integer(7));
81 assert_eq!(Value::float(1.25), Value::Float(1.25));
82 assert_eq!(Value::text("abc"), Value::Text("abc".to_owned()));
83 assert_eq!(
84 Value::blob_base64("AQID"),
85 Value::BlobBase64("AQID".to_owned())
86 );
87 }
88}