1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
use crate::IconAnchor;
use std::fmt;

#[derive(Clone)]
pub struct MarkerIcon<S: AsRef<str> + Clone> {
    anchor: Option<IconAnchor>,
    url: S,
}

impl<S: AsRef<str> + Clone> MarkerIcon<S> {
    pub fn new(url: S) -> Self {
        MarkerIcon { anchor: None, url }
    }

    pub fn position(&self, anchor: IconAnchor) -> Self {
        MarkerIcon {
            anchor: Some(anchor),
            ..(*self).clone()
        }
    }
}

impl<S: AsRef<str> + Clone> fmt::Display for MarkerIcon<S> {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        let mut parts: Vec<String> = vec![];

        if let Some(anchor) = &self.anchor {
            parts.push(format!("anchor:{}", anchor.to_string()));
        }

        parts.push(format!("icon:{}", self.url.as_ref()));

        write!(f, "{}", parts.join("|"))
    }
}