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
26
27
28
29
30
31
32
33
use super::Manifest;

pub struct AssetPath {
    dir: String,
    file: String, 
}

impl AssetPath {
    pub fn new<S>(dir: S, file_key: S, manifest: &Manifest) -> Self 
    where S: Into<String> {
        let file = file_key.into();
        AssetPath {
            dir: dir.into(),
            file: manifest.get(&file)
                .expect(&format!("File key '{}' not found in file manifest!", &file))
                .to_owned()
        }
    }
}

impl<'a> From<AssetPath> for String {
    fn from(t: AssetPath) -> String {
         format!("{}{}", t.dir.trim_end_matches('/'), t.file)
    }
}

#[test]
fn test_asset_path() {
    let mut manifest = Manifest::new();
    manifest.insert("asdf".into(), "/qwerty".into());
    let file = AssetPath::new("public", "asdf", &manifest);
    assert_eq!(&String::from(file), "public/qwerty");
}