use sha2::{Digest, Sha256}; use std::collections::HashMap; use std::fs; use std::iter::FromIterator; use std::fmt::Write; pub fn get() -> HashMap { let paths = fs::read_dir("assets").unwrap().map(|e| { let path = format!("{}", e.unwrap().path().display()); let file = fs::read(&path).unwrap(); let mut path_iter = path.split('/'); path_iter.next(); let name = path_iter.collect::>().join("/"); let hashed = format!("/assets/{}/{}", sha256(file), name); (name, hashed) }); HashMap::from_iter(paths) } fn sha256(input: Vec) -> String { let mut hasher = Sha256::new(); hasher.update(input); let mut res = String::new(); for byte in hasher.finalize().iter() { write!(&mut res, "{:x}", byte).unwrap(); } res }