use std::path::Path;
pub fn path_to_forward_slash_string(path: &Path) -> String {
path.components()
.filter_map(|c| match c {
std::path::Component::Normal(s) => s.to_str().map(|v| v.to_string()),
_ => None,
})
.collect::<Vec<String>>()
.join("/")
}
pub fn logical_path_for_file_input(path: &Path, cwd: &Path) -> String {
if path.is_relative() {
return path_to_forward_slash_string(path);
}
if let Ok(rel) = path.strip_prefix(cwd) {
let s = path_to_forward_slash_string(rel);
if !s.is_empty() {
return s;
}
}
path.file_name()
.and_then(|s| s.to_str())
.unwrap_or("input.bin")
.to_string()
}