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.
toml
smart-pathbuf = "0.4"
The PathBuf
methods that are nightly only now are behind a feature flag and can
be enabled.
toml
smart-pathbuf = { version = "0.3", features = ["unstable"] }
As std lib stabilize these features so will this crate.
No more calling multiple .pop()
.
```rust
use smart_path::SmartPathBuf;
let dir = std::env::currentdir().expect("failed"); let mut spath = SmartPathBuf::from(&dir); //or just spath = SmartPathBuf::from(&dir); // spath.push(&dir);
spath.push("to/file"); dosomething(&s_path); // "current/dir/to/file"
// remove segments up to the initial path given spath.initial(); // or spath.poplast(); // "current/dir" spath.push("another/file"); domore(&spath); ```
SmartPathBuf
can be manipulated with indexes and ranges.
rust
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.
Pull requests or suggestions welcome!