~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.
73dab7ba
—
Costin-Robert Sin 1 year ago
Replace `expect` with a safer alternative that returns `None` instead
- utils/src/lib.rs +11 -12
utils/src/lib.rs
CHANGED
|
@@ -146,18 +146,17 @@ pub fn read_file_from_fs(file_path: &Path) -> io::Result<EmbeddedFile> {
|
|
|
146
146
|
};
|
|
147
147
|
|
|
148
148
|
let metadata = fs::metadata(file_path)?;
|
|
149
|
-
let last_modified = metadata
|
|
149
|
+
let last_modified = metadata
|
|
150
|
-
|
|
150
|
+
.modified()
|
|
151
|
+
.ok()
|
|
151
|
-
|
|
152
|
+
.and_then(|modified| modified.duration_since(SystemTime::UNIX_EPOCH).ok())
|
|
152
|
-
.expect("Time before the UNIX epoch is unsupported")
|
|
153
|
-
|
|
153
|
+
.map(|secs| secs.as_secs());
|
|
154
|
-
|
|
154
|
+
|
|
155
|
-
let created = metadata
|
|
155
|
+
let created = metadata
|
|
156
|
-
created
|
|
156
|
+
.created()
|
|
157
|
+
.ok()
|
|
157
|
-
|
|
158
|
+
.and_then(|created| created.duration_since(SystemTime::UNIX_EPOCH).ok())
|
|
158
|
-
.expect("Time before the UNIX epoch is unsupported")
|
|
159
|
-
|
|
159
|
+
.map(|secs| secs.as_secs());
|
|
160
|
-
});
|
|
161
160
|
|
|
162
161
|
#[cfg(feature = "mime-guess")]
|
|
163
162
|
let mimetype = mime_guess::from_path(file_path).first_or_octet_stream().to_string();
|