This crate implements the TrimmablePath trait on std::path::Path so you can easily obtain the last n parts of a path.
text
// in Cargo.toml
[dependencies]
pathtrim = "1.0.0"
```rust use std::path::Path; // at the top of your source file use pathtrim::TrimmablePath;
// TrimmablePath is automatically implemented for all std::path::Paths in scope let path = Path::new("/usr/local/bin/"); let trimmed = path.trimtonth(2);
assert!(trimmed.issome()); asserteq!(trimmed.unwrap().to_str().unwrap(), "local/bin");
let trimmed = path.trimtonth(2000); assert!(trimmed.is_none());
```