~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. examples/rocket.rs +2 -2
  2. examples/warp.rs +1 -3
  3. impl/src/lib.rs +1 -1
examples/rocket.rs CHANGED
@@ -33,8 +33,8 @@ fn dist<'r>(file: PathBuf) -> response::Result<'r> {
33
33
  .as_path()
34
34
  .extension()
35
35
  .and_then(OsStr::to_str)
36
- .ok_or(Status::new(400, "Could not get file extension"))?;
36
+ .ok_or_else(|| Status::new(400, "Could not get file extension"))?;
37
- let content_type = ContentType::from_extension(ext).ok_or(Status::new(400, "Could not get file content type"))?;
37
+ let content_type = ContentType::from_extension(ext).ok_or_else(|| Status::new(400, "Could not get file content type"))?;
38
38
  response::Response::build().header(content_type).sized_body(Cursor::new(d)).ok()
39
39
  },
40
40
  )
examples/warp.rs CHANGED
@@ -1,5 +1,3 @@
1
- #![deny(warnings)]
2
-
3
1
  extern crate rust_embed;
4
2
  extern crate warp;
5
3
 
@@ -27,7 +25,7 @@ fn serve(path: &str) -> Result<impl Reply, Rejection> {
27
25
 
28
26
  let asset: Option<Cow<'static, [u8]>> = Asset::get(path);
29
27
 
30
- let file = asset.ok_or_else(|| warp::reject::not_found())?;
28
+ let file = asset.ok_or_else(warp::reject::not_found)?;
31
29
 
32
30
  Ok(Response::builder().header("content-type", mime.to_string()).body(file))
33
31
  }
impl/src/lib.rs CHANGED
@@ -158,7 +158,7 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> TokenStream2 {
158
158
 
159
159
  // Add a message about the interpolate-folder-path feature if the path may
160
160
  // include a variable
161
- if folder_path.contains("$") && cfg!(not(feature = "interpolate-folder-path")) {
161
+ if folder_path.contains('$') && cfg!(not(feature = "interpolate-folder-path")) {
162
162
  message += "\nA variable has been detected. RustEmbed can expand variables \
163
163
  when the `interpolate-folder-path` feature is enabled.";
164
164
  }