#[derive(Debug, Clone)]
pub struct PathContext<'a> {
pub parent: &'a str,
pub file: &'a str,
}
impl<'a> PathContext<'a> {
pub fn from(path: &'a str) -> Self {
let clean_path = path.trim_start_matches("./");
let (parent, file) = match clean_path.rfind('/') {
Some(idx) => {
(&clean_path[..idx], &clean_path[idx + 1..])
}
None => {
("", clean_path)
}
};
Self { parent, file }
}
pub fn name(&self) -> &'a str { self.file }
pub fn parent(&self) -> &'a str { self.parent }
pub fn is_root_level(&self) -> bool { self.parent.is_empty() }
}