A convenience wrapper for `PathBuf` `SmartPathBuf`

After working with Path a bit I thought something like this might come in handy SmartPathBuf. This crate tries to remove a lot of the verbose manipulation that comes with navigating folders and files with the PathBuf and Path structs.

let mut path = PathBuf::from("some/folder");
path.push("more/more/file.ext");

use_path(&path);
path.pop();
path.pop();
path.pop();

path.push("some_other_folder/another_file.ext");
use_path(&path);
// ect...

can now be simplified to

let mut path = SmartPathBuf::from("some/folder");
path.push("more/more/file.ext");

use_path(&path);
// any of these 3 
// initial always resets path to original or first push
// in this case "some/folder"
path.initial();
// removes the last pushed segments
path.pop_last();
// uses Range to slice and return new `SmartPathBuf`
let new_path = path.range(..2);

path.push("some_other_folder/another_file.ext");
use_path(&path);

If anyone has any other ideas/features github to make fix any problems that you have with paths in rust!!

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.