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
use std::str::FromStr;
use serde::{Deserialize, Serialize};
use crate::{BigDecimal, Dict, List, Number, Text};
mod json;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub enum Object {
Default,
Boolean(bool),
Number(Number),
Reference(String),
Text(Text),
List(List),
Dict(Dict),
}
impl From<&str> for Object {
fn from(value: &str) -> Self {
Object::text(value, "")
}
}
impl From<&String> for Object {
fn from(value: &String) -> Self {
Object::text(value, "")
}
}
impl From<String> for Object {
fn from(value: String) -> Self {
Object::text(value, "")
}
}
impl Object {
pub fn text(text: impl Into<String>, hint: impl Into<String>) -> Self {
Object::Text(Text { hint: hint.into(), value: text.into() })
}
pub fn number(number: impl Into<BigDecimal>, hint: impl Into<String>) -> Self {
Object::Number(Number { hint: hint.into(), value: number.into() })
}
}