diff --git a/src/build.rs b/src/build.rs index b6dfdd3..180cce0 100644 --- a/src/build.rs +++ b/src/build.rs @@ -1,5 +1,6 @@ use std::env; use std::fs::{read_dir, File}; +use std::io::ErrorKind::NotFound; use std::io::Read; use std::io::Write; use std::path::{Path, PathBuf}; @@ -20,24 +21,34 @@ pub fn create_static_output_files(source_dir: &str) { let out_dir = env::var("OUT_DIR").unwrap(); let dest_path = Path::new(&out_dir).join("static_files.rs"); let mut f = File::create(&dest_path).unwrap(); - for maybe_dir_entry in read_dir(source_dir).unwrap() { - let file_path = maybe_dir_entry.unwrap().path(); - let mut buffer = String::new(); - File::open(file_path.clone()) - .unwrap() - .read_to_string(&mut buffer) - .unwrap(); - let fence = buffer.chars().filter(|c| *c == '#').collect::() + "#"; - f.write_all( - format!( - "pub const {}: &str = r{1}\"{2}\"{1};\n", - get_const_name(&file_path), - fence, - buffer - ) - .as_bytes(), - ) - .unwrap(); + match read_dir(source_dir) { + Ok(dir_content) => { + for maybe_dir_entry in dir_content { + let file_path = maybe_dir_entry.unwrap().path(); + let mut buffer = String::new(); + File::open(file_path.clone()) + .unwrap() + .read_to_string(&mut buffer) + .unwrap(); + let fence = buffer.chars().filter(|c| *c == '#').collect::() + "#"; + f.write_all( + format!( + "pub const {}: &str = r{1}\"{2}\"{1};\n", + get_const_name(&file_path), + fence, + buffer + ) + .as_bytes(), + ) + .unwrap(); + } + } + Err(err) => { + if err.kind() == NotFound { + } else { + Err(err).unwrap() + } + } } }