1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// use std::path::{Component, Path, PathBuf};
//
// pub struct PathPrefixes<'a> {
// path: &'a Path,
// idx: usize,
// }
//
// impl<'a> PathPrefixes<'a> {
// pub fn new(path: &'a Path) -> Self {
// Self {
// path,
// idx: 0,
// }
// }
// }
//
// impl Iterator for PathPrefixes<'_> {
// type Item = PathBuf;
//
// fn next(&mut self) -> Option<Self::Item> {
// if self.idx > self.path.components().count() {
// return None;
// }
// self.idx += 1;
//
// let res = self.path.components().take(self.idx).fold(PathBuf::new(),
// |acc: PathBuf, c: Component| {
// acc.join(c)
// });
//
// Some(res)
// }
// }
//
// #[cfg(test)]
// mod tests {
// use std::path::PathBuf;
//
// use crate::experiments::path_prefixes::PathPrefixes;
//
// #[test]
// fn test_some_prefixes() {
// let path = PathBuf::from("/some/path/file.txt");
//
// let mut pp = PathPrefixes::new(path.as_path());
//
// assert_eq!(pp.next(), Some(PathBuf::from("/")));
// assert_eq!(pp.next(), Some(PathBuf::from("/some")));
// assert_eq!(pp.next(), Some(PathBuf::from("/some/path")));
// assert_eq!(pp.next(), None);
// }
// }