wordchipper_disk_cache/
path_utils.rs1use std::path::{Path, PathBuf};
4
5pub fn extend_path<P, S, F>(
14 path: P,
15 context: &[S],
16 filename: F,
17) -> PathBuf
18where
19 P: AsRef<Path>,
20 S: AsRef<Path>,
21 F: AsRef<Path>,
22{
23 let mut path = path.as_ref().to_path_buf();
24 path.extend(context.iter().map(|s| s.as_ref()));
25 path.push(filename.as_ref());
26 path
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32
33 #[test]
34 fn test_extend_path() {
35 let path = extend_path("/tmp/wordchipper", &["cache", "data"], "file.txt");
36 assert_eq!(path, PathBuf::from("/tmp/wordchipper/cache/data/file.txt"));
37 }
38}