use sha2::{Digest, Sha256}; use std::collections::HashMap; use std::fs; use std::iter::FromIterator; 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); hasher .finalize() .iter() .map(|b| format!("{:x}", b)) .collect() }