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
use nemesis::Error; use std::borrow::Cow; use std::collections::HashMap; #[derive(RustEmbed)] #[folder = "$CARGO_MANIFEST_DIR/static"] pub struct Assets; impl Assets { pub fn all() -> Result<HashMap<String, Vec<u8>>, Error> { let mut assets = HashMap::default(); for source in Self::iter() { let content = Self::get(&source) .map(Cow::into_owned) .ok_or_else(|| Error::FailedLaunch(format!("missing static asset {}", source)))?; if source == "index.html" { let route = "/".to_owned(); assets.insert(route, content.clone()); } let route = format!("/{}", source); assets.insert(route, content); } Ok(assets) } }