Expand description
This crate provides the Poppable trait for removing the last component of Path-like things. It is intended for use in situations where you don’t know whether you’ll have a Path or a PathBuf and don’t want to do an additional allocation.
use poppable_path::Poppable;
trait PathGenerator<'a> {
/// Something path-like that may depend on the lifetime `'a`
type Path: Poppable + AsRef<std::path::Path>;
fn path(&'a self) -> Self::Path;
fn dir(&'a self) -> Option<Self::Path> {
let mut path = self.path();
if path.as_ref().is_dir() {
Some(path)
} else if !path.pop() {
None
} else if path.as_ref().is_dir() {
Some(path)
} else {
None
}
}
}