charming_fork_zephyr/component/
geo_map.rs

1use serde::Serialize;
2
3#[derive(Serialize)]
4pub enum GeoMapOpt {
5    #[serde(rename = "geoJSON")]
6    GeoJson {
7        value: serde_json::Value,
8        special_areas: serde_json::Value,
9    },
10    #[serde(rename = "svg")]
11    Svg(String),
12}
13
14impl<S> From<S> for GeoMapOpt
15where
16    S: Into<String>,
17{
18    fn from(s: S) -> Self {
19        GeoMapOpt::Svg(s.into())
20    }
21}
22
23#[derive(Serialize)]
24#[serde(rename_all = "camelCase")]
25pub struct GeoMap {
26    #[serde(skip_serializing_if = "Option::is_none")]
27    name: Option<String>,
28
29    #[serde(skip_serializing_if = "Option::is_none")]
30    opt: Option<GeoMapOpt>,
31}
32
33impl GeoMap {
34    pub fn new() -> Self {
35        GeoMap {
36            name: None,
37            opt: None,
38        }
39    }
40
41    pub fn map_name<S: Into<String>>(mut self, name: S) -> Self {
42        self.name = Some(name.into());
43        self
44    }
45
46    pub fn opt<M: Into<GeoMapOpt>>(mut self, opt: M) -> Self {
47        self.opt = Some(opt.into());
48        self
49    }
50}
51
52impl From<&str> for GeoMap {
53    fn from(svg: &str) -> Self {
54        GeoMap::new().opt(GeoMapOpt::Svg(svg.to_string()))
55    }
56}
57
58impl From<(&str, &str)> for GeoMap {
59    fn from((name, svg): (&str, &str)) -> Self {
60        GeoMap::new()
61            .map_name(name.to_string())
62            .opt(GeoMapOpt::Svg(svg.to_string()))
63    }
64}