smart-path

Crates.iosmart-path
lib.rssmart-path
version0.4.1
sourcesrc
created_at2019-10-16 13:18:07.365975
updated_at2019-10-18 02:29:08.791128
descriptionWrapper to extend PathBuf's functionality
homepage
repositoryhttps://github.com/DevinR528/smart-pathbuf
max_upload_size
id172996
size32,804
Devin Ragotzy (DevinR528)

documentation

README

Smart PathBuf

Build Status Latest Version Latest Version

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!

Commit count: 17

cargo fmt