std_ext/
path.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
use std::path::Path;

pub trait PathExt {
    fn ext_str(&self) -> &str;
    fn file_name_str(&self) -> &str;
}

impl PathExt for Path {
    fn ext_str(&self) -> &str {
        self.extension()
            .and_then(|ext| ext.to_str())
            .unwrap_or_default()
    }

    fn file_name_str(&self) -> &str {
        self.file_name()
            .and_then(|name| name.to_str())
            .unwrap_or_default()
    }
}