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