diff options
author | Till Höppner | 2016-02-18 18:53:30 +0100 |
---|---|---|
committer | Till Höppner | 2016-02-18 18:53:30 +0100 |
commit | aea35fa7e1a3261e5e7a3e8daa999bed3dcd193f (patch) | |
tree | 6f010c750dd390a5cbbb6c935603b14f800d6d7c /src | |
parent | 7808afe883904650a012ce1ccf8ff596aa294c4b (diff) | |
download | includedir-aea35fa7e1a3261e5e7a3e8daa999bed3dcd193f.tar.gz includedir-aea35fa7e1a3261e5e7a3e8daa999bed3dcd193f.tar.xz includedir-aea35fa7e1a3261e5e7a3e8daa999bed3dcd193f.zip |
Restructure, add API, add compression
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 52 |
1 files changed, 0 insertions, 52 deletions
diff --git a/src/lib.rs b/src/lib.rs deleted file mode 100644 index 939b958..0000000 --- a/src/lib.rs +++ /dev/null @@ -1,52 +0,0 @@ -extern crate walkdir; -extern crate phf_codegen; - -use std::{env, io}; -use std::fs::File; -use std::io::{BufWriter, Write}; -use std::path::Path; - -use walkdir::WalkDir; - -pub fn build<P: AsRef<Path>>(dir: P) -> io::Result<()> { - let dir = dir.as_ref(); - - let base_path = Path::new(&env::var("CARGO_MANIFEST_DIR").unwrap()).to_owned(); - - let dir_name = dir.file_name().expect("Invalid directory name").to_string_lossy(); - let out_name = format!("dir_{}.rs", dir_name); - let out_path = Path::new(&env::var("OUT_DIR").unwrap()).join(out_name); - let mut out_file = BufWriter::new(File::create(&out_path).unwrap()); - - write!(&mut out_file, - "static FILES: phf::Map<&'static str, &'static [u8]> = ") - .unwrap(); - - // FIXME: rustfmt mangles this - let entries: Vec<(String, String)> = WalkDir::new(dir) - .into_iter() - .filter(|e| { - !e.as_ref() - .ok() - .map_or(true, |e| e.file_type().is_dir()) - }) - .map(|e| { - let entry = e.expect("Invalid dir entry."); - let name = format!("{}", entry.path().display()); - let code = format!("include_bytes!(\"{}\") \ - as &'static [u8]", - base_path.join(entry.path()) - .display()); - (name, code) - }) - .collect(); - - let mut map: phf_codegen::Map<&str> = phf_codegen::Map::new(); - for &(ref name, ref code) in &entries { - map.entry(name, code); - } - map.build(&mut out_file).unwrap(); - - write!(&mut out_file, ";\n").unwrap(); - Ok(()) -} |