1use std::path::{Path, PathBuf};
3
4pub fn output_path(
9 input: &Path,
10 suffix: Option<&str>,
11 prefix: Option<&str>,
12 outdir: Option<&Path>,
13) -> PathBuf {
14 let stem = input.file_stem().unwrap_or_default().to_string_lossy();
15 let ext = input.extension().unwrap_or_default().to_string_lossy();
16
17 let filename = match suffix {
18 Some(s) => format!("{stem}.{s}.{ext}"),
19 None => format!("{stem}.{ext}"),
20 };
21 let filename = match prefix {
22 Some(p) => format!("{p}{filename}"),
23 None => filename,
24 };
25
26 let dir = outdir.unwrap_or_else(|| input.parent().unwrap_or(Path::new(".")));
27 dir.join(filename)
28}