1use indexmap::IndexMap;
2use serde::Serialize;
3
4#[derive(Debug, Clone, Default, Serialize)]
6pub struct Params {
7 #[serde(flatten)]
8 options: IndexMap<&'static str, Value>,
9}
10
11impl Params {
12 pub fn extend(&mut self, other: Self) {
14 self.options.extend(other.options)
15 }
16
17 pub fn insert(&mut self, name: &'static str, value: Value) -> Option<Value> {
19 self.options.insert(name, value)
20 }
21
22 pub fn iter(&self) -> impl Iterator<Item = (&'static str, &Value)> {
24 self.options.iter().map(|(name, value)| (*name, value))
25 }
26}
27
28impl IntoIterator for Params {
29 type Item = (&'static str, Value);
30 type IntoIter = <IndexMap<&'static str, Value> as IntoIterator>::IntoIter;
31
32 fn into_iter(self) -> Self::IntoIter {
33 self.options.into_iter()
34 }
35}
36
37impl FromIterator<(&'static str, Value)> for Params {
38 fn from_iter<T>(iter: T) -> Self
39 where
40 T: IntoIterator<Item = (&'static str, Value)>,
41 {
42 Self {
43 options: iter.into_iter().collect(),
44 }
45 }
46}
47
48#[derive(Debug, Clone, Serialize)]
50#[serde(untagged)]
51pub enum Value {
52 Bool(bool),
53 Int(i64),
54 Uint(u64),
55 Float(f64),
56
57 String(&'static str),
65 Nested(IndexMap<&'static str, Value>),
66
67 #[cfg(feature = "proc-macro")]
69 OwnedString(String),
70 #[cfg(feature = "proc-macro")]
71 OwnedNested(IndexMap<String, Value>),
72}