crabtime-internal 1.1.4

Helper for the crabtime crate.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
use crate::error::*;
use std::path::Path;

pub fn parent(path: &Path) -> Result<&Path> {
    path.parent().context(|| error!("Path '{}' does not have a parent.", path.display()))
}

pub fn find_parent<'t>(path: &'t Path, dir_name: &str) -> Result<&'t Path> {
    let dir_name_os = std::ffi::OsStr::new(dir_name);
    path.ancestors()
        .find(|p| p.file_name() == Some(dir_name_os))
        .context(|| error!(
            "Path '{}' does not have parent '{dir_name}' directory.",
            path.display()
        ))
}