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


9f7aa882 Mark Drobnak

6 years ago
Merge pull request #91 from paolobarbolini/update-deps1
Files changed (2) hide show
  1. Cargo.toml +2 -2
  2. examples/actix.rs +13 -8
Cargo.toml CHANGED
@@ -15,8 +15,8 @@ walkdir = "2.2.7"
15
15
  rust-embed-impl = { version = "5.1.0", path = "impl"}
16
16
  rust-embed-utils = { version = "5.0.0", path = "utils"}
17
17
 
18
- actix-web = { version = "0.7", optional = true }
18
+ actix-web = { version = "1", optional = true }
19
- mime_guess = { version = "2.0.0-alpha.6", optional = true }
19
+ mime_guess = { version = "2", optional = true }
20
20
  warp = { version = "0.1", optional = true }
21
21
  rocket = { version = "0.4.2", optional = true }
22
22
 
examples/actix.rs CHANGED
@@ -3,9 +3,9 @@ extern crate actix_web;
3
3
  extern crate rust_embed;
4
4
  extern crate mime_guess;
5
5
 
6
- use actix_web::http::Method;
6
+ use actix_web::body::Body;
7
- use actix_web::{server, App, Body, HttpRequest, HttpResponse};
7
+ use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
8
- use mime_guess::guess_mime_type;
8
+ use mime_guess::from_path;
9
9
  use std::borrow::Cow;
10
10
 
11
11
  #[derive(RustEmbed)]
@@ -19,7 +19,7 @@ fn handle_embedded_file(path: &str) -> HttpResponse {
19
19
  Cow::Borrowed(bytes) => bytes.into(),
20
20
  Cow::Owned(bytes) => bytes.into(),
21
21
  };
22
- HttpResponse::Ok().content_type(guess_mime_type(path).as_ref()).body(body)
22
+ HttpResponse::Ok().content_type(from_path(path).first_or_octet_stream().as_ref()).body(body)
23
23
  }
24
24
  None => HttpResponse::NotFound().body("404 Not Found"),
25
25
  }
@@ -35,8 +35,13 @@ fn dist(req: HttpRequest) -> HttpResponse {
35
35
  }
36
36
 
37
37
  fn main() {
38
+ HttpServer::new(|| {
39
+ App::new()
40
+ .service(web::resource("/").route(web::get().to(index)))
38
- server::new(|| App::new().route("/", Method::GET, index).route("/dist/{_:.*}", Method::GET, dist))
41
+ .service(web::resource("/dist/{_:.*}").route(web::get().to(dist)))
42
+ })
39
- .bind("127.0.0.1:8000")
43
+ .bind("127.0.0.1:8000")
40
- .unwrap()
44
+ .unwrap()
41
- .run();
45
+ .run()
46
+ .unwrap();
42
47
  }