1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
use super::os_string_display::OsStringDisplay;
use std::path::{Component::*, Path};
pub fn path_name(path: &Path) -> OsStringDisplay {
match path.components().last() {
None | Some(CurDir) => OsStringDisplay::os_string_from("."),
Some(Normal(name)) => OsStringDisplay::os_string_from(name),
Some(Prefix(prefix)) => OsStringDisplay::os_string_from(prefix.as_os_str()),
Some(RootDir) | Some(ParentDir) => OsStringDisplay::os_string_from(path),
}
}
#[cfg(test)]
mod test_path_name;