~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/axum.rs +4 -9
examples/axum.rs CHANGED
@@ -1,5 +1,6 @@
1
1
  use axum::{
2
+ extract::Path,
2
- http::{header, StatusCode, Uri},
3
+ http::{header, StatusCode},
3
4
  response::{Html, IntoResponse, Response},
4
5
  routing::{get, Router},
5
6
  };
@@ -25,19 +26,13 @@ async fn main() {
25
26
  // We use static route matchers ("/" and "/index.html") to serve our home
26
27
  // page.
27
28
  async fn index_handler() -> impl IntoResponse {
28
- static_handler("/index.html".parse::<Uri>().unwrap()).await
29
+ static_handler(Path("index.html".to_string())).await
29
30
  }
30
31
 
31
32
  // We use a wildcard matcher ("/dist/*file") to match against everything
32
33
  // within our defined assets directory. This is the directory on our Asset
33
34
  // struct below, where folder = "examples/public/".
34
- async fn static_handler(uri: Uri) -> impl IntoResponse {
35
+ async fn static_handler(Path(path): Path<String>) -> impl IntoResponse {
35
- let mut path = uri.path().trim_start_matches('/').to_string();
36
-
37
- if path.starts_with("dist/") {
38
- path = path.replace("dist/", "");
39
- }
40
-
41
36
  StaticFile(path)
42
37
  }
43
38