cpp_pack/
lib.rs

1use std::ffi::OsStr;
2use std::fs;
3use std::path::{PathBuf, Path};
4
5mod write_zip;
6
7fn valid_extention(ext: &OsStr) -> bool {
8    ["cpp", "h", "txt"].iter().map(OsStr::new).any(|x| ext == x)
9}
10
11pub fn pack_project(dir: &Path) {
12    let paths: Vec<PathBuf> = fs::read_dir(dir)
13        .expect("Failed to read directory.")
14        .filter_map(|x| x.ok())
15        .map(|x| x.path())
16        .filter(|x| match x.extension() {
17            None => false,
18            Some(ext) => valid_extention(ext),
19        })
20        .collect();
21
22    write_zip::copy_to_zip(
23        dir.join("submission").with_extension("zip"),
24        &paths,
25    );
26}
27
28