Skip to content

Commit a735c9e

Browse files
authored
Merge pull request #240 from costinsin/fix_expect
Replace `expect` with a safer alternative that returns `None` instead
2 parents f7c7268 + 73dab7b commit a735c9e

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

utils/src/lib.rs

+11-12
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,17 @@ pub fn read_file_from_fs(file_path: &Path) -> io::Result<EmbeddedFile> {
146146
};
147147

148148
let metadata = fs::metadata(file_path)?;
149-
let last_modified = metadata.modified().ok().map(|last_modified| {
150-
last_modified
151-
.duration_since(SystemTime::UNIX_EPOCH)
152-
.expect("Time before the UNIX epoch is unsupported")
153-
.as_secs()
154-
});
155-
let created = metadata.created().ok().map(|created| {
156-
created
157-
.duration_since(SystemTime::UNIX_EPOCH)
158-
.expect("Time before the UNIX epoch is unsupported")
159-
.as_secs()
160-
});
149+
let last_modified = metadata
150+
.modified()
151+
.ok()
152+
.and_then(|modified| modified.duration_since(SystemTime::UNIX_EPOCH).ok())
153+
.map(|secs| secs.as_secs());
154+
155+
let created = metadata
156+
.created()
157+
.ok()
158+
.and_then(|created| created.duration_since(SystemTime::UNIX_EPOCH).ok())
159+
.map(|secs| secs.as_secs());
161160

162161
#[cfg(feature = "mime-guess")]
163162
let mimetype = mime_guess::from_path(file_path).first_or_octet_stream().to_string();

0 commit comments

Comments
 (0)