cargo_mobile2/bicycle/json_map.rs
1use handlebars::to_json;
2use serde::Serialize;
3use serde_json::value::{Map, Value as Json};
4
5/// Map of template variable names and values.
6#[derive(Clone, Debug)]
7#[repr(transparent)]
8pub struct JsonMap(pub(crate) Map<String, Json>);
9
10impl Default for JsonMap {
11 fn default() -> Self {
12 Self(Map::new())
13 }
14}
15
16impl JsonMap {
17 pub fn insert(&mut self, name: &str, value: impl Serialize) {
18 self.0.insert(name.to_owned(), to_json(value));
19 }
20}