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


af538b52 Peter

6 years ago
Merge pull request #71 from AletiCodes/utils-fix
Cargo.toml CHANGED
@@ -13,6 +13,7 @@ authors = ["pyros2097 <pyros2097@gmail.com>"]
13
13
  [dependencies]
14
14
  walkdir = "2.2.7"
15
15
  rust-embed-impl = { version = "4.5.0", path = "impl"}
16
+ rust-embed-utils = { version = "4.5.0", path = "utils"}
16
17
 
17
18
  actix-web = { version = "0.7", optional = true }
18
19
  mime_guess = { version = "2.0.0-alpha.6", optional = true }
@@ -20,7 +21,7 @@ warp = { version = "0.1", optional = true }
20
21
  rocket = { version = "0.4.2", optional = true }
21
22
 
22
23
  [features]
23
- debug-embed = ["rust-embed-impl/debug-embed"]
24
+ debug-embed = ["rust-embed-impl/debug-embed", "rust-embed-utils/debug-embed"]
24
25
  interpolate-folder-path = ["rust-embed-impl/interpolate-folder-path"]
25
26
  nightly = ["rocket"]
26
27
  actix = ["actix-web", "mime_guess"]
impl/Cargo.toml CHANGED
@@ -14,6 +14,8 @@ authors = ["pyros2097 <pyros2097@gmail.com>"]
14
14
  proc-macro = true
15
15
 
16
16
  [dependencies]
17
+ rust-embed-utils = { version = "4.5.0", path = "../utils"}
18
+
17
19
  syn = "0.11"
18
20
  quote = "0.3"
19
21
  walkdir = "2.2.7"
impl/src/lib.rs CHANGED
@@ -13,7 +13,6 @@ use quote::Tokens;
13
13
  use std::path::Path;
14
14
  use syn::*;
15
15
 
16
- mod utils;
17
16
 
18
17
  #[cfg(all(debug_assertions, not(feature = "debug-embed")))]
19
18
  fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
@@ -42,8 +41,8 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
42
41
 
43
42
  pub fn iter() -> impl Iterator<Item = std::borrow::Cow<'static, str>> {
44
43
  use std::path::Path;
45
- use rust_embed::utils::get_files;
44
+ extern crate rust_embed_utils;
46
- get_files(String::from(#folder_path)).map(|e| std::borrow::Cow::from(e.rel_path))
45
+ rust_embed_utils::get_files(String::from(#folder_path)).map(|e| std::borrow::Cow::from(e.rel_path))
47
46
  }
48
47
  }
49
48
  impl rust_embed::RustEmbed for #ident {
@@ -60,12 +59,12 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
60
59
 
61
60
  #[cfg(any(not(debug_assertions), feature = "debug-embed"))]
62
61
  fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
63
- use utils::{get_files, FileEntry};
62
+ extern crate rust_embed_utils;
64
63
 
65
64
  let mut match_values = Vec::<Tokens>::new();
66
65
  let mut list_values = Vec::<String>::new();
67
66
 
68
- for FileEntry { rel_path, full_canonical_path } in get_files(folder_path) {
67
+ for rust_embed_utils::FileEntry { rel_path, full_canonical_path } in rust_embed_utils::get_files(folder_path) {
69
68
  match_values.push(quote! {
70
69
  #rel_path => {
71
70
  let bytes = &include_bytes!(#full_canonical_path)[..];
impl/src/utils.rs DELETED
@@ -1 +0,0 @@
1
- ../../src/utils.rs
src/lib.rs CHANGED
@@ -6,10 +6,6 @@ extern crate walkdir;
6
6
  extern crate rust_embed_impl;
7
7
  pub use rust_embed_impl::*;
8
8
 
9
- #[doc(hidden)]
10
- #[cfg(all(debug_assertions, not(feature = "debug-embed")))]
11
- pub mod utils;
12
-
13
9
  /// A directory of binary assets.
14
10
  ///
15
11
  /// They should be embedded into the executable for release builds,
utils/Cargo.toml ADDED
@@ -0,0 +1,17 @@
1
+ [package]
2
+ name = "rust-embed-utils"
3
+ version = "4.5.0"
4
+ description = "Utilities for rust-embed"
5
+ readme = "readme.md"
6
+ documentation = "https://docs.rs/rust-embed"
7
+ repository = "https://github.com/pyros2097/rust-embed"
8
+ license = "MIT"
9
+ keywords = ["http", "rocket", "static", "web", "server"]
10
+ categories = ["web-programming::http-server"]
11
+ authors = ["pyros2097 <pyros2097@gmail.com>"]
12
+
13
+ [dependencies]
14
+ walkdir = "2.2.7"
15
+
16
+ [features]
17
+ debug-embed = []
utils/readme.md ADDED
@@ -0,0 +1,3 @@
1
+ # Rust Embed Utilities
2
+
3
+ The utilities used by rust-embed and rust-embed-impl lie here.
src/utils.rs → utils/src/lib.rs RENAMED
@@ -1,4 +1,5 @@
1
+ #[cfg(all(debug_assertions, not(feature = "debug-embed")))]
1
- use std;
2
+ extern crate walkdir;
2
3
 
3
4
  #[cfg_attr(all(debug_assertions, not(feature = "debug-embed")), allow(unused))]
4
5
  pub struct FileEntry {
@@ -8,8 +9,6 @@ pub struct FileEntry {
8
9
 
9
10
  #[cfg_attr(all(debug_assertions, not(feature = "debug-embed")), allow(unused))]
10
11
  pub fn get_files(folder_path: String) -> impl Iterator<Item = FileEntry> {
11
- use std;
12
- use walkdir;
13
12
  walkdir::WalkDir::new(&folder_path)
14
13
  .into_iter()
15
14
  .filter_map(|e| e.ok())