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
use crate::{impl_scalar_internal, Result, Scalar, Value};
use std::ops::{Deref, DerefMut};
#[derive(Clone, Ord, PartialOrd, Eq, PartialEq, Hash, Debug)]
pub struct ID(String);
impl Deref for ID {
type Target = String;
fn deref(&self) -> &Self::Target {
&self.0
}
}
impl DerefMut for ID {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
impl From<String> for ID {
fn from(value: String) -> Self {
ID(value)
}
}
impl<'a> From<&'a str> for ID {
fn from(value: &'a str) -> Self {
ID(value.to_string())
}
}
impl From<usize> for ID {
fn from(value: usize) -> Self {
ID(value.to_string())
}
}
impl Scalar for ID {
fn type_name() -> &'static str {
"ID"
}
fn parse(value: &Value) -> Option<Self> {
match value {
Value::Int(n) => Some(ID(n.as_i64().unwrap().to_string())),
Value::String(s) => Some(ID(s.clone())),
_ => None,
}
}
fn to_json(&self) -> Result<serde_json::Value> {
Ok(self.0.clone().into())
}
}
impl_scalar_internal!(ID);