~repos /rust-embed

#rust#proc-macro#http

git clone https://pyrossh.dev/repos/rust-embed.git
Discussions: https://groups.google.com/g/rust-embed-devs

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


Files changed (3) hide show
  1. Cargo.lock +1 -1
  2. Cargo.toml +1 -1
  3. src/lib.rs +8 -8
Cargo.lock CHANGED
@@ -13,7 +13,7 @@ dependencies = [
13
13
 
14
14
  [[package]]
15
15
  name = "rust-embed"
16
- version = "0.3.4"
16
+ version = "0.3.5"
17
17
  dependencies = [
18
18
  "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
19
19
  "walkdir 2.1.4 (registry+https://github.com/rust-lang/crates.io-index)",
Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rust-embed"
3
- version = "0.3.4"
3
+ version = "0.3.5"
4
4
  description = "Rust Marco which loads files into the rust binary at compile time during release and loads the file from the fs during dev"
5
5
  readme = "readme.md"
6
6
  documentation = "https://docs.rs/rust-embed"
src/lib.rs CHANGED
@@ -7,16 +7,16 @@ fn generate_assets(parent_path: String) -> Box<Fn(String) -> Option<Vec<u8>>> {
7
7
  use std::fs::File;
8
8
  use std::path::Path;
9
9
  use std::io::Read;
10
- info!("rust-embed: loading folder -> {}", parent_path);
10
+ info!("loading folder -> {}", parent_path);
11
11
  Box::new(move |file_path| {
12
12
  let name = &format!("{}{}", parent_path, file_path);
13
13
  let path = &Path::new(name);
14
14
  let key = String::from(path.to_str().expect("Path does not have a string representation"));
15
- info!("rust-embed: asset from file -> {}", key);
15
+ info!("asset from file -> {}", key);
16
16
  let mut file = match File::open(path) {
17
17
  Ok(mut file) => file,
18
18
  Err(e) => {
19
- error!("rust-embed: could not open file -> {} {}", key, e);
19
+ error!("could not open file -> {} {}", key, e);
20
20
  return None
21
21
  }
22
22
  };
@@ -24,7 +24,7 @@ fn generate_assets(parent_path: String) -> Box<Fn(String) -> Option<Vec<u8>>> {
24
24
  match file.read_to_end(&mut data) {
25
25
  Ok(_) => Some(data),
26
26
  Err(e) => {
27
- error!("rust-embed: could not open file -> {} {}", key, e);
27
+ error!("could not open file -> {} {}", key, e);
28
28
  return None
29
29
  }
30
30
  }
@@ -39,18 +39,18 @@ fn generate_assets<'a>(parent_path: String) -> Box<Fn(String) -> Option<Vec<u8>>
39
39
  use walkdir::WalkDir;
40
40
  use std::collections::HashMap;
41
41
 
42
- info!("rust-embed: loading folder -> {}", parent_path);
42
+ info!("loading folder -> {}", parent_path);
43
43
  let mut map = HashMap::new();
44
44
  for entry in WalkDir::new(parent_path.clone()).into_iter().filter_map(|e| e.ok()).filter(|e| e.file_type().is_file()) {
45
- info!("rust-embed: asset from file -> {}", entry.path().display());
45
+ info!("asset from file -> {}", entry.path().display());
46
46
  let base = &parent_path.clone();
47
47
  let key = String::from(entry.path().to_str().expect("Path does not have a string representation")).replace(base, "");
48
48
  let mut file = File::open(&Path::new(&entry.path())).unwrap_or_else(|e| {
49
- panic!("rust-embed: could not open file -> {} {}", key, e);
49
+ panic!("could not open file -> {} {}", key, e);
50
50
  });
51
51
  let mut data: Vec<u8> = Vec::new();
52
52
  file.read_to_end(&mut data).unwrap_or_else(|e| {
53
- panic!("rust-embed: could not read file -> {} {}", key, e);
53
+ panic!("could not read file -> {} {}", key, e);
54
54
  });
55
55
  map.insert(key, data);
56
56
  }