1use indexmap::IndexMap;
2use serde::Serialize;
3use std::borrow::Cow;
4use std::collections::HashMap;
5use std::fmt::{Display, Formatter};
6
7pub use crate::de::{from_slice, from_str};
8pub use crate::parser::{parse, Rule};
9
10pub mod error;
11mod parser;
12
13mod de;
14#[cfg(any(
15 feature = "lua51",
16 feature = "lua52",
17 feature = "lua53",
18 feature = "lua54",
19 feature = "luajit",
20 feature = "luajit52"
21))]
22mod lua;
23#[cfg(feature = "wasm")]
24mod wasm;
25
26pub type Inputs<'a> = HashMap<&'a str, Value<'a>>;
29
30pub type Object<'a> = IndexMap<Cow<'a, str>, Value<'a>>;
32
33#[derive(Serialize, Debug, Clone)]
34#[serde(untagged)]
35pub enum Value<'a> {
36 Object(Object<'a>),
38 Array(Vec<Value<'a>>),
40 String(Cow<'a, str>),
42 Integer(i64),
44 Float(f64),
46 Boolean(bool),
48 Null(Option<()>),
54}
55
56impl<'a> Display for Value<'a> {
57 fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
58 write!(
59 f,
60 "{}",
61 match self {
62 Value::Object(_) => "object",
63 Value::Array(_) => "array",
64 Value::String(_) => "string",
65 Value::Integer(_) => "integer",
66 Value::Float(_) => "float",
67 Value::Boolean(_) => "boolean",
68 Value::Null(_) => "null",
69 }
70 )
71 }
72}