4 releases
0.4.1 | Oct 18, 2019 |
---|---|
0.4.0 | Oct 17, 2019 |
0.3.1 | Oct 16, 2019 |
0.3.0 | Oct 16, 2019 |
#1509 in Filesystem
33KB
709 lines
Smart PathBuf
A wrapper around rust's PathBuf
adding convenience methods for manipulating paths. SmartPathBuf
has all the same functionality as PathBuf
and more, it is an extension and will always maintain feature
parity with PathBuf
. SmartPathBuf
will add some overhead as it needs to keep more information around,
I will work to keep it as low as possible.
Use
smart-pathbuf = "0.4"
The PathBuf
methods that are nightly only now are behind a feature flag and can
be enabled.
smart-pathbuf = { version = "0.3", features = ["unstable"] }
As std lib stabilize these features so will this crate.
Examples
No more calling multiple .pop()
.
use smart_path::SmartPathBuf;
let dir = std::env::current_dir().expect("failed");
let mut s_path = SmartPathBuf::from(&dir);
//or just s_path = SmartPathBuf::from(&dir);
// s_path.push(&dir);
s_path.push("to/file");
do_something(&s_path); // "current/dir/to/file"
// remove segments up to the initial path given
s_path.initial();
// or s_path.pop_last();
// "current/dir"
s_path.push("another/file");
do_more(&s_path);
SmartPathBuf
can be manipulated with indexes and ranges.
let mut path = SmartPathBuf::from("hello/world/bye");
let p = path.range(..path.len() - 1);
assert_eq!(p.as_path(), PathBuf::from("hello/world").as_path());
Or slice from the middle to end SmartPathBuf
will handle slicing absolute paths
returning a non absolute path.
Contribute
Pull requests or suggestions welcome!