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


0bb1f1c4 BBaoVanC

2 years ago
Rewrite mimetype interpolation
Files changed (1) hide show
  1. impl/src/lib.rs +8 -3
impl/src/lib.rs CHANGED
@@ -175,9 +175,14 @@ fn embed_file(rel_path: &str, full_canonical_path: &str) -> TokenStream2 {
175
175
  None => quote! { None },
176
176
  };
177
177
  #[cfg(feature = "mime-guess")]
178
+ let mimetype_tokens = {
178
- let mimetype = file.metadata.mimetype();
179
+ let mt = file.metadata.mimetype();
180
+ quote! {
181
+ , #mt
182
+ }
183
+ };
179
184
  #[cfg(not(feature = "mime-guess"))]
180
- let mimetype = quote! { None };
185
+ let mimetype_tokens = TokenStream2::new();
181
186
 
182
187
  let embedding_code = if cfg!(feature = "compression") {
183
188
  quote! {
@@ -196,7 +201,7 @@ fn embed_file(rel_path: &str, full_canonical_path: &str) -> TokenStream2 {
196
201
 
197
202
  Some(rust_embed::EmbeddedFile {
198
203
  data: std::borrow::Cow::from(bytes),
199
- metadata: rust_embed::Metadata::__rust_embed_new([#(#hash),*], #last_modified, #mimetype)
204
+ metadata: rust_embed::Metadata::__rust_embed_new([#(#hash),*], #last_modified #mimetype_tokens)
200
205
  })
201
206
  }
202
207
  }