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


5d983bd5 Mark Drobnak

6 years ago
Merge pull request #81 from pyros2097/tweak/shell-expand-help-message
Files changed (2) hide show
  1. examples/warp.rs +1 -1
  2. impl/src/lib.rs +12 -4
examples/warp.rs CHANGED
@@ -22,7 +22,7 @@ fn main() {
22
22
  }
23
23
 
24
24
  fn serve(path: &str) -> Result<impl Reply, Rejection> {
25
- let mime = mime_guess::guess_mime_type(path);
25
+ let mime = mime_guess::from_path(path).first_or_octet_stream();
26
26
 
27
27
  let asset: Option<Cow<'static, [u8]>> = Asset::get(path);
28
28
 
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
-
17
16
  #[cfg(all(debug_assertions, not(feature = "debug-embed")))]
18
17
  fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
19
18
  quote! {
@@ -107,8 +106,8 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> Tokens {
107
106
  match ast.body {
108
107
  Body::Enum(_) => panic!("RustEmbed cannot be derived for enums"),
109
108
  Body::Struct(ref data) => match data {
110
- &VariantData::Unit => {},
109
+ &VariantData::Unit => {}
111
- _ => panic!("RustEmbed can only be derived for unit structs")
110
+ _ => panic!("RustEmbed can only be derived for unit structs"),
112
111
  },
113
112
  };
114
113
 
@@ -128,11 +127,20 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> Tokens {
128
127
  let folder_path = shellexpand::full(&folder_path).unwrap().to_string();
129
128
 
130
129
  if !Path::new(&folder_path).exists() {
131
- panic!(
130
+ let mut message = format!(
132
131
  "#[derive(RustEmbed)] folder '{}' does not exist. cwd: '{}'",
133
132
  folder_path,
134
133
  std::env::current_dir().unwrap().to_str().unwrap()
135
134
  );
135
+
136
+ // Add a message about the interpolate-folder-path feature if the path may
137
+ // include a variable
138
+ if folder_path.contains("$") && cfg!(not(feature = "interpolate-folder-path")) {
139
+ message += "\nA variable has been detected. RustEmbed can expand variables \
140
+ when the `interpolate-folder-path` feature is enabled.";
141
+ }
142
+
143
+ panic!(message);
136
144
  };
137
145
 
138
146
  generate_assets(&ast.ident, folder_path)