1use super::Manifest;
2
3pub struct AssetPath {
4 dir: String,
5 file: String,
6}
7
8impl AssetPath {
9 pub fn new<S>(dir: S, file_key: S, manifest: &Manifest) -> Self
10 where S: Into<String> {
11 let file = file_key.into();
12 AssetPath {
13 dir: dir.into(),
14 file: manifest.get(&file)
15 .expect(&format!("File key '{}' not found in file manifest!", &file))
16 .to_owned()
17 }
18 }
19}
20
21impl<'a> From<AssetPath> for String {
22 fn from(t: AssetPath) -> String {
23 format!("{}{}", t.dir.trim_end_matches('/'), t.file)
24 }
25}
26
27#[test]
28fn test_asset_path() {
29 let mut manifest = Manifest::new();
30 manifest.insert("asdf".into(), "/qwerty".into());
31 let file = AssetPath::new("public", "asdf", &manifest);
32 assert_eq!(&String::from(file), "public/qwerty");
33}