~repos /rust-embed
git clone https://pyrossh.dev/repos/rust-embed.git
rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.
d1843470
—
Jasper van Herpt 3 years ago
Fetch metadata when a folder is fetched instead of a file
- tests/lib.rs +1 -0
- tests/metadata.rs +11 -0
- utils/src/lib.rs +1 -1
tests/lib.rs
CHANGED
|
@@ -10,6 +10,7 @@ fn get_works() {
|
|
|
10
10
|
assert!(Asset::get("index.html").is_some(), "index.html should exist");
|
|
11
11
|
assert!(Asset::get("gg.html").is_none(), "gg.html should not exist");
|
|
12
12
|
assert!(Asset::get("images/llama.png").is_some(), "llama.png should exist");
|
|
13
|
+
assert!(Asset::get("images").is_some(), "images should exist");
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
/// Using Windows-style path separators (`\`) is acceptable
|
tests/metadata.rs
CHANGED
|
@@ -25,3 +25,14 @@ fn last_modified_is_accurate() {
|
|
|
25
25
|
|
|
26
26
|
assert_eq!(index_file.metadata.last_modified(), Some(expected_datetime_utc));
|
|
27
27
|
}
|
|
28
|
+
|
|
29
|
+
#[test]
|
|
30
|
+
fn is_dir_is_accurate() {
|
|
31
|
+
let index_file: EmbeddedFile = Asset::get("index.html").expect("index.html exists");
|
|
32
|
+
let doc_file: EmbeddedFile = Asset::get("images/doc.txt").expect("doc.txt exists");
|
|
33
|
+
let images_folder: EmbeddedFile = Asset::get("images/").expect("images exists");
|
|
34
|
+
|
|
35
|
+
assert_eq!(index_file.metadata.is_dir(), false);
|
|
36
|
+
assert_eq!(doc_file.metadata.is_dir(), false);
|
|
37
|
+
assert!(images_folder.metadata.is_dir());
|
|
38
|
+
}
|
utils/src/lib.rs
CHANGED
|
@@ -114,7 +114,7 @@ impl Metadata {
|
|
|
114
114
|
}
|
|
115
115
|
|
|
116
116
|
pub fn read_file_from_fs(file_path: &Path) -> io::Result<EmbeddedFile> {
|
|
117
|
-
let data = fs::read(file_path)?;
|
|
117
|
+
let data = if !file_path.is_dir() { fs::read(file_path)? } else { Vec::new() };
|
|
118
118
|
let data = Cow::from(data);
|
|
119
119
|
|
|
120
120
|
let mut hasher = sha2::Sha256::new();
|