cargo_mobile2/bicycle/
json_map.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use handlebars::to_json;
use serde::Serialize;
use serde_json::value::{Map, Value as Json};

/// Map of template variable names and values.
#[derive(Clone, Debug)]
#[repr(transparent)]
pub struct JsonMap(pub(crate) Map<String, Json>);

impl Default for JsonMap {
    fn default() -> Self {
        Self(Map::new())
    }
}

impl JsonMap {
    pub fn insert(&mut self, name: &str, value: impl Serialize) {
        self.0.insert(name.to_owned(), to_json(value));
    }
}