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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
use mime_guess; /// Add an icon to the web manifest. /// /// ## Example Output /// ```json /// "icons": [{ /// "src": "images/touch/homescreen48.png", /// "sizes": "48x48", /// "type": "image/png" /// }, { /// "src": "images/touch/homescreen72.png", /// "sizes": "72x72", /// "type": "image/png" /// }, { /// "src": "images/touch/homescreen96.png", /// "sizes": "96x96", /// "type": "image/png" /// }, { /// "src": "images/touch/homescreen144.png", /// "sizes": "144x144", /// "type": "image/png" /// }, { /// "src": "images/touch/homescreen168.png", /// "sizes": "168x168", /// "type": "image/png" /// }, { /// "src": "images/touch/homescreen192.png", /// "sizes": "192x192", /// "type": "image/png" /// }], /// ``` #[derive(Debug, Clone, Serialize, Deserialize)] pub struct Icon<'s> { src: &'s str, sizes: &'s str, #[serde(rename = "type")] icon_type: String, } impl<'s> Icon<'s> { /// Create a new `Icon` instance. /// /// ## Example /// ```rust /// # extern crate webmanifest; /// # use webmanifest::Icon; /// let src = "images/touch/homescreen48.png"; /// let icon = Icon::new(&src, "48x48"); /// ``` #[must_use] #[inline] pub fn new(src: &'s str, sizes: &'s str) -> Self { let icon_type = mime_guess::guess_mime_type(&src).to_string(); Self { src, sizes, icon_type, } } }