~repos /rust-embed
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.
24737392
—
Paolo Barbolini 6 years ago
Update dependencies for examples
- Cargo.toml +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 = "
|
|
18
|
+
actix-web = { version = "1", optional = true }
|
|
19
|
-
mime_guess = { version = "2
|
|
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::
|
|
6
|
+
use actix_web::body::Body;
|
|
7
|
-
use actix_web::{
|
|
7
|
+
use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
|
|
8
|
-
use mime_guess::
|
|
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(
|
|
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
|
-
|
|
41
|
+
.service(web::resource("/dist/{_:.*}").route(web::get().to(dist)))
|
|
42
|
+
})
|
|
39
|
-
|
|
43
|
+
.bind("127.0.0.1:8000")
|
|
40
|
-
|
|
44
|
+
.unwrap()
|
|
41
|
-
|
|
45
|
+
.run()
|
|
46
|
+
.unwrap();
|
|
42
47
|
}
|