std_ext/
path.rs

1use std::path::Path;
2
3pub trait PathExt {
4    fn ext_str(&self) -> &str;
5    fn file_name_str(&self) -> &str;
6}
7
8impl PathExt for Path {
9    fn ext_str(&self) -> &str {
10        self.extension()
11            .and_then(|ext| ext.to_str())
12            .unwrap_or_default()
13    }
14
15    fn file_name_str(&self) -> &str {
16        self.file_name()
17            .and_then(|name| name.to_str())
18            .unwrap_or_default()
19    }
20}