~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 (1) hide show
  1. examples/actix.rs +4 -5
examples/actix.rs CHANGED
@@ -1,5 +1,5 @@
1
1
  use actix_web::body::Body;
2
- use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
2
+ use actix_web::{web, App, HttpResponse, HttpServer};
3
3
  use mime_guess::from_path;
4
4
  use rust_embed::RustEmbed;
5
5
 
@@ -22,13 +22,12 @@ fn handle_embedded_file(path: &str) -> HttpResponse {
22
22
  }
23
23
  }
24
24
 
25
- fn index(_req: HttpRequest) -> HttpResponse {
25
+ fn index() -> HttpResponse {
26
26
  handle_embedded_file("index.html")
27
27
  }
28
28
 
29
- fn dist(req: HttpRequest) -> HttpResponse {
29
+ fn dist(path: web::Path<(String,)>) -> HttpResponse {
30
- let path = &req.path()["/dist/".len()..]; // trim the preceding `/dist/` in path
31
- handle_embedded_file(path)
30
+ handle_embedded_file(&path.0)
32
31
  }
33
32
 
34
33
  #[actix_rt::main]