gmaps_static/
marker_icon.rs

1use crate::IconAnchor;
2use std::fmt;
3
4#[derive(Clone)]
5pub struct MarkerIcon<S: AsRef<str> + Clone> {
6    anchor: Option<IconAnchor>,
7    url: S,
8}
9
10impl<S: AsRef<str> + Clone> MarkerIcon<S> {
11    pub fn new(url: S) -> Self {
12        MarkerIcon { anchor: None, url }
13    }
14
15    pub fn position(&self, anchor: IconAnchor) -> Self {
16        MarkerIcon {
17            anchor: Some(anchor),
18            ..(*self).clone()
19        }
20    }
21}
22
23impl<S: AsRef<str> + Clone> fmt::Display for MarkerIcon<S> {
24    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25        let mut parts: Vec<String> = vec![];
26
27        if let Some(anchor) = &self.anchor {
28            parts.push(format!("anchor:{}", anchor.to_string()));
29        }
30
31        parts.push(format!("icon:{}", self.url.as_ref()));
32
33        write!(f, "{}", parts.join("|"))
34    }
35}