use std::path::PathBuf; use std::fs; #[derive(Debug)] pub enum FileType { HtmlIndex(PathBuf), NeovanIndex(PathBuf), HtmlComponent(PathBuf), NeovanComponent(PathBuf) } impl FileType { pub fn get_all(dir: PathBuf) -> Vec { let entries = fs::read_dir(dir).expect("Create failed"); let mut files = Vec::new(); for entry in entries { let path = entry.expect("Failed to read directory").path(); if path.is_dir() { files.append(&mut FileType::get_all(path)); } else if path.is_file() { let filename = path.file_name().expect("Error reading file").to_string_lossy(); if filename == "index.html" { files.push(FileType::HtmlIndex(path)) } else if filename == "index.neovan" { files.push(FileType::NeovanIndex(path)) } else if let Some(ext) = path.extension() { if ext == "html" { files.push(FileType::HtmlComponent(path)) } else if ext == "neovan" { files.push(FileType::NeovanComponent(path)) } } } } files } }