pub trait PathExt: AsRef<Path> {
    fn cleanup(&self) -> PathBuf { ... }
}
Expand description

Utility methods for std::path::Path[Buf]

Provided methods

Cleanup/simplify path as much as possible

Examples
use mmrbi::PathExt;

assert_eq!(Path::new("a/b").cleanup(),                      Path::new("a/b"));
assert_eq!(Path::new("a/b/..").cleanup(),                   Path::new("a"));
assert_eq!(Path::new("a/b/../..").cleanup(),                Path::new("."));
assert_eq!(Path::new("a/b/../../..").cleanup(),             Path::new(".."));
assert_eq!(Path::new("a/b/../../../..").cleanup(),          Path::new("../.."));

assert_eq!(Path::new("../../a/b").cleanup(),                Path::new("../../a/b"));
assert_eq!(Path::new("../../a/b/..").cleanup(),             Path::new("../../a"));
assert_eq!(Path::new("../../a/b/../..").cleanup(),          Path::new("../.."));
assert_eq!(Path::new("../../a/b/../../..").cleanup(),       Path::new("../../.."));
assert_eq!(Path::new("../../a/b/../../../..").cleanup(),    Path::new("../../../.."));

if cfg!(windows) {
    assert_eq!(Path::new(r"C:\foo\bar").cleanup(),          Path::new(r"C:\foo\bar"));
    assert_eq!(Path::new(r"\\?\C:\foo\bar").cleanup(),      Path::new(r"C:\foo\bar"));
}

Implementors