~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.


0fd4ff2b pyros2097

7 years ago
fix release bundling and release v1.1.0
Files changed (6) hide show
  1. .travis.yml +6 -2
  2. Cargo.lock +1 -1
  3. Cargo.toml +1 -1
  4. readme.md +1 -1
  5. rustfmt.toml +9 -0
  6. src/lib.rs +13 -19
.travis.yml CHANGED
@@ -12,5 +12,9 @@ matrix:
12
12
  script:
13
13
  - |
14
14
  cargo clean
15
- cargo test --lib
15
+ cargo test --tests --lib
16
- cargo test --lib --release
16
+ cargo test --tests --lib --release
17
+ cargo clean
18
+ cargo build --example basic
19
+ cargo clean
20
+ cargo build --release --example basic
Cargo.lock CHANGED
@@ -714,7 +714,7 @@ dependencies = [
714
714
 
715
715
  [[package]]
716
716
  name = "rust-embed"
717
- version = "1.0.0"
717
+ version = "1.1.0"
718
718
  dependencies = [
719
719
  "fern 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)",
720
720
  "log 0.4.1 (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 = "1.0.0"
3
+ version = "1.1.0"
4
4
  description = "Rust Custom Derive Macro 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"
readme.md CHANGED
@@ -11,7 +11,7 @@ This is similar to [pony-embed](https://github.com/pyros2097/pony-embed).
11
11
 
12
12
  ```
13
13
  [dependencies]
14
- rust-embed="1.0.0"
14
+ rust-embed="1.1.0"
15
15
  ```
16
16
 
17
17
  ## Documentation
rustfmt.toml ADDED
@@ -0,0 +1,9 @@
1
+ unstable_features = true
2
+ wrap_comments = true
3
+ normalize_comments = true
4
+ merge_derives = true
5
+ fn_args_density = "Compressed"
6
+ max_width = 160
7
+ tab_spaces = 2
8
+ indent_style = "Block"
9
+ reorder_imported_names = true
src/lib.rs CHANGED
@@ -1,4 +1,6 @@
1
1
  #![recursion_limit = "1024"]
2
+ #[macro_use]
3
+ extern crate log;
2
4
  extern crate proc_macro;
3
5
  #[macro_use]
4
6
  extern crate quote;
@@ -45,21 +47,19 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
45
47
  }
46
48
 
47
49
  #[cfg(not(debug_assertions))]
48
- pub fn generate_assets(folder_path: String) -> Asset {
50
+ fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
49
51
  use std::fs::File;
50
52
  use std::io::Read;
51
53
  use std::path::Path;
52
54
  use walkdir::WalkDir;
53
- use std::collections::HashMap;
54
- info!("loading folder -> {}", parent_path);
55
- let mut map = HashMap::new();
55
+ let mut values = Vec::<Tokens>::new();
56
- for entry in WalkDir::new(parent_path.clone())
56
+ for entry in WalkDir::new(folder_path.clone())
57
57
  .into_iter()
58
58
  .filter_map(|e| e.ok())
59
59
  .filter(|e| e.file_type().is_file())
60
60
  {
61
- info!("asset from file -> {}", entry.path().display());
61
+ info!("file: {}", entry.path().display());
62
- let base = &parent_path.clone();
62
+ let base = &folder_path.clone();
63
63
  let key = String::from(
64
64
  entry
65
65
  .path()
@@ -73,20 +73,16 @@ pub fn generate_assets(folder_path: String) -> Asset {
73
73
  file.read_to_end(&mut data).unwrap_or_else(|e| {
74
74
  panic!("could not read file -> {} {}", key, e);
75
75
  });
76
+ let value = quote!{
76
- map.insert(key, data);
77
+ #key => Some(vec!#data),
78
+ };
79
+ values.push(value);
77
80
  }
78
- Box::new(move |file_path| {
79
- info!("asset from cache -> {}", file_path);
80
- match map.get(&file_path) {
81
- Some(s) => Some(s.to_vec()),
82
- None => None,
83
- }
84
- });
85
81
  quote!{
86
82
  impl #ident {
87
83
  pub fn get(file_path: &str) -> Option<Vec<u8>> {
88
84
  match file_path {
89
- "index.html" => Some(vec![]),
85
+ #(#values)*
90
86
  _ => None,
91
87
  }
92
88
  }
@@ -95,9 +91,7 @@ pub fn generate_assets(folder_path: String) -> Asset {
95
91
  }
96
92
 
97
93
  fn help() {
98
- panic!(
99
- "#[derive(RustEmbed)] should contain one attribute like this #[golem(\"examples/public/\")]"
94
+ panic!("#[derive(RustEmbed)] should contain one attribute like this #[golem(\"examples/public/\")]");
100
- );
101
95
  }
102
96
 
103
97
  fn impl_rust_embed(ast: &syn::DeriveInput) -> Tokens {