Skip to main content

normalize

Function normalize 

Source
pub fn normalize(path: &Path) -> PathBuf
Expand description

Normalize path to collapse “..”, “.”, and duplicate separators. This function does not access the filesystem, so it can return an incorrect result if the path contains symlinks.

assert_eq!(normalize("foo/.//bar/../baz/".as_ref()), Path::new("foo/baz"));

// Interesting edge cases:
assert_eq!(normalize("".as_ref()), Path::new("."));
assert_eq!(normalize("..".as_ref()), Path::new(".."));
assert_eq!(normalize("/..".as_ref()), Path::new("/"));

This behavior matches that of Python’s os.path.normpath and Go’s path.Clean.