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
use std::collections::HashSet;
use std::path::Path;
use std::io;
use std::fs::read_dir;

pub trait AbstractFilesystem {
    fn file_names_in(&self, rel_path: &str) -> io::Result<HashSet<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<HashSet<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())
    }
}