Skip to content

Wrapper for easy manipulation of rust's Path and PathBuf's.

Notifications You must be signed in to change notification settings

DevinR528/smart-pathbuf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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!

About

Wrapper for easy manipulation of rust's Path and PathBuf's.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages