1#![cfg(feature = "std")]
6
7pub use self::fs::*;
8
9pub fn project_root() -> std::path::PathBuf {
11 std::path::Path::new(&env!("CARGO_MANIFEST_DIR"))
12 .ancestors()
13 .nth(1)
14 .unwrap()
15 .to_path_buf()
16}
17
18mod fs {
19 use std::fs::File;
20 use std::io::{self, BufRead, BufReader};
21 pub fn collect_files_as<T>(f: &dyn Fn(std::path::PathBuf) -> T, pat: &str) -> Vec<T> {
23 let mut files = Vec::<T>::new();
24 for path in glob::glob(pat).expect("Failed to read glob pattern...") {
25 if let Ok(r) = path {
26 files.push(f(r))
27 }
28 continue;
29 }
30 files
31 }
32
33 pub fn file_to_vec(fp: String) -> Result<Vec<String>, io::Error> {
35 let file_in = File::open(fp)?;
36 let file_reader = BufReader::new(file_in);
37 Ok(file_reader.lines().filter_map(Result::ok).collect())
38 }
39}