Crates.io | path-clean |
lib.rs | path-clean |
version | 1.0.1 |
source | src |
created_at | 2018-11-06 01:13:18.641954 |
updated_at | 2023-02-24 03:24:24.388366 |
description | A Rust implementation of cleanname or path.Clean |
homepage | |
repository | https://github.com/danreeves/path-clean |
max_upload_size | |
id | 94943 |
size | 13,281 |
cargo add path-clean
use std::path::PathBuf;
use path_clean::{clean, PathClean};
assert_eq!(clean("hello/world/.."), PathBuf::from("hello"));
assert_eq!(
PathBuf::from("/test/../path/").clean(),
PathBuf::from("/path")
);
path-clean
is a Rust port of the the cleanname
procedure from the Plan 9 C library, and is similar to path.Clean
from the Go standard library. It works as follows:
.
path name elements (the current directory)...
path name elements (the parent directory) and the non-.
non-..
, element that precedes them...
elements that begin a rooted path, that is, replace /..
by /
at the beginning of a path...
elements that begin a non-rooted path.If the result of this process is an empty string, return the string "."
, representing the current directory.
It performs this transform lexically, without touching the filesystem. Therefore it doesn't do any symlink resolution or absolute path resolution. For more information you can see "Getting Dot-Dot Right".
For convenience, the [PathClean
] trait is exposed and comes implemented for [std::path::PathBuf
].
MIT OR Apache-2.0