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
use std::collections::BTreeSet;
use std::fs::read_dir;
use std::io;
use std::path::Path;
pub trait AbstractFilesystem {
fn file_names_in(&self, rel_path: &str) -> io::Result<BTreeSet<Box<str>>>;
}
pub struct Filesystem<'a> {
path: &'a Path,
}
impl<'a> Filesystem<'a> {
pub fn new(path: &'a Path) -> Self {
Self { path }
}
}
impl<'a> AbstractFilesystem for Filesystem<'a> {
fn file_names_in(&self, rel_path: &str) -> io::Result<BTreeSet<Box<str>>> {
Ok(read_dir(self.path.join(rel_path))?
.filter_map(|entry| {
entry
.ok()
.map(|e| e.file_name().to_string_lossy().to_string().into_boxed_str())
})
.collect())
}
}