fn cwd_rel_to_workspace_rel()

in tools/cargo-hakari/src/command.rs [436:455]


fn cwd_rel_to_workspace_rel(path: &Utf8Path, workspace_root: &Utf8Path) -> Result<Utf8PathBuf> {
    let abs_path = if path.is_absolute() {
        path.to_owned()
    } else {
        let cwd = std::env::current_dir().with_context(|| "could not access current dir")?;
        let mut cwd = Utf8PathBuf::try_from(cwd).with_context(|| "current dir is invalid UTF-8")?;
        cwd.push(path);
        cwd
    };

    abs_path
        .strip_prefix(workspace_root)
        .map(|p| p.to_owned())
        .with_context(|| {
            format!(
                "path {} is not inside workspace root {}",
                abs_path, workspace_root
            )
        })
}