~repos /rust-embed

#rust#proc-macro#http

git clone https://pyrossh.dev/repos/rust-embed.git

rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.


3e640137 pyros2097

7 years ago
use strip_prefix closes #35
Files changed (1) hide show
  1. src/lib.rs +3 -4
src/lib.rs CHANGED
@@ -23,17 +23,16 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
23
23
  let folder_path = #folder_path;
24
24
  let name = &format!("{}{}", folder_path, file_path);
25
25
  let path = &Path::new(name);
26
- let key = String::from(path.to_str().expect("Path does not have a string representation"));
27
26
  let mut file = match File::open(path) {
28
27
  Ok(mut file) => file,
29
- Err(e) => {
28
+ Err(_e) => {
30
29
  return None
31
30
  }
32
31
  };
33
32
  let mut data: Vec<u8> = Vec::new();
34
33
  match file.read_to_end(&mut data) {
35
34
  Ok(_) => Some(data),
36
- Err(e) => {
35
+ Err(_e) => {
37
36
  return None
38
37
  }
39
38
  }
@@ -52,7 +51,7 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
52
51
  .filter(|e| e.file_type().is_file())
53
52
  {
54
53
  let base = &folder_path.clone();
55
- let key = String::from(entry.path().to_str().expect("Path does not have a string representation")).replace(base, "");
54
+ let key = String::from(entry.path().strip_prefix(base).unwrap().to_str().expect("Path does not have a string representation"));
56
55
  let canonical_path = std::fs::canonicalize(entry.path()).expect("Could not get canonical path");
57
56
  let canonical_path_str = canonical_path.to_str();
58
57
  let value = quote!{