scalar_doc/
favicon.rs

1use std::fmt::Display;
2
3#[derive(Clone, Debug)]
4pub enum FaviconMimeType {
5    /// .ico (image/x-icon)
6    Ico,
7    /// .png (image/png)
8    Png,
9    /// .svg (image/svg+xml)
10    Svg,
11    /// .gif (image/gif)
12    Gif,
13    /// .jpg (image/jpeg)
14    Jpeg,
15    /// .webp (image/webp)
16    Webp
17}
18
19impl Display for FaviconMimeType {
20    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
21        match self {
22            Self::Ico => write!(f, "image/x-icon"),
23            Self::Png => write!(f, "image/png"),
24            Self::Svg => write!(f, "image/svg+xml"),
25            Self::Gif => write!(f, "image/gif"),
26            Self::Jpeg => write!(f, "image/jpeg"),
27            Self::Webp => write!(f, "image/webp")
28        }
29    }
30}
31
32/// Favicon for a documentation page
33///
34/// **Default** - ``favicon.ico`` (FaviconMimeType::Ico)
35#[derive(Clone, Debug)]
36pub struct Favicon {
37    favicon: String,
38    mime: FaviconMimeType
39}
40
41impl Favicon {
42    pub fn new(favicon: String, mime: FaviconMimeType) -> Self {
43        Self { favicon, mime }
44    }
45
46    pub fn favicon(&self) -> &String {
47        &self.favicon
48    }
49
50    pub fn mime(&self) -> String {
51        self.mime.to_string()
52    }
53}
54
55impl Default for Favicon {
56    fn default() -> Self {
57        Self {
58            favicon: String::from("favicon.ico"),
59            mime: FaviconMimeType::Ico
60        }
61    }
62}