assets.rs

1.1 kB · rust · 35 lines

1/// The font as glyph tables in JSON.2pub const JSON: &[u8] = include_bytes!("../assets/MrlyFont.json");34/// The font as a TrueType binary.5pub const TTF: &[u8] = include_bytes!("../assets/MrlyFont.ttf");67/// The font packed as WOFF.8pub const WOFF: &[u8] = include_bytes!("../assets/MrlyFont.woff");910/// The font packed as WOFF2.11pub const WOFF2: &[u8] = include_bytes!("../assets/MrlyFont.woff2");1213/// Returns the bytes and mime type of a named format, or None when the name is not one of json, ttf, woff, woff2.14pub fn format(name: &str) -> Option<(&'static [u8], &'static str)> {15    match name {16        "json" => Some((JSON, "application/json")),17        "ttf" => Some((TTF, "font/ttf")),18        "woff" => Some((WOFF, "font/woff")),19        "woff2" => Some((WOFF2, "font/woff2")),20        _ => None,21    }22}2324#[cfg(test)]25mod tests {26    #[test]27    fn every_format_carries_bytes() {28        for name in ["json", "ttf", "woff", "woff2"] {29            let (bytes, mime) = super::format(name).expect("a known format");30            assert!(!bytes.is_empty());31            assert!(!mime.is_empty());32        }33        assert!(super::format("otf").is_none());34    }35}