| Crates.io | smart-path |
| lib.rs | smart-path |
| version | 0.4.1 |
| created_at | 2019-10-16 13:18:07.365975+00 |
| updated_at | 2019-10-18 02:29:08.791128+00 |
| description | Wrapper to extend PathBuf's functionality |
| homepage | |
| repository | https://github.com/DevinR528/smart-pathbuf |
| max_upload_size | |
| id | 172996 |
| size | 32,804 |
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.
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.
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.
Pull requests or suggestions welcome!