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


eb42c093 Paolo Barbolini

5 years ago
rustc: upgrade to the 2018 edition
Cargo.toml CHANGED
@@ -9,6 +9,7 @@ license = "MIT"
9
9
  keywords = ["http", "rocket", "static", "web", "server"]
10
10
  categories = ["web-programming::http-server"]
11
11
  authors = ["pyros2097 <pyros2097@gmail.com>"]
12
+ edition = "2018"
12
13
 
13
14
  [dependencies]
14
15
  walkdir = "2.2.7"
examples/actix.rs CHANGED
@@ -1,7 +1,3 @@
1
- extern crate actix_web;
2
- extern crate mime_guess;
3
- extern crate rust_embed;
4
-
5
1
  use actix_web::body::Body;
6
2
  use actix_web::{web, App, HttpRequest, HttpResponse, HttpServer};
7
3
  use mime_guess::from_path;
examples/basic.rs CHANGED
@@ -1,5 +1,3 @@
1
- extern crate rust_embed;
2
-
3
1
  use rust_embed::RustEmbed;
4
2
 
5
3
  #[derive(RustEmbed)]
examples/rocket.rs CHANGED
@@ -1,7 +1,6 @@
1
1
  #![feature(decl_macro, proc_macro_hygiene)]
2
2
  #[macro_use]
3
3
  extern crate rocket;
4
- extern crate rust_embed;
5
4
 
6
5
  use rocket::http::{ContentType, Status};
7
6
  use rocket::response;
examples/warp.rs CHANGED
@@ -1,6 +1,3 @@
1
- extern crate rust_embed;
2
- extern crate warp;
3
-
4
1
  use rust_embed::RustEmbed;
5
2
  use warp::{filters::path::Tail, http::Response, Filter, Rejection, Reply};
6
3
 
impl/Cargo.toml CHANGED
@@ -9,6 +9,7 @@ license = "MIT"
9
9
  keywords = ["http", "rocket", "static", "web", "server"]
10
10
  categories = ["web-programming::http-server"]
11
11
  authors = ["pyros2097 <pyros2097@gmail.com>"]
12
+ edition = "2018"
12
13
 
13
14
  [lib]
14
15
  proc-macro = true
impl/src/lib.rs CHANGED
@@ -1,12 +1,7 @@
1
1
  #![recursion_limit = "1024"]
2
- extern crate proc_macro;
3
2
  #[macro_use]
4
3
  extern crate quote;
5
- extern crate syn;
6
-
7
- #[cfg(feature = "interpolate-folder-path")]
8
- extern crate shellexpand;
9
- extern crate walkdir;
4
+ extern crate proc_macro;
10
5
 
11
6
  use proc_macro::TokenStream;
12
7
  use std::path::Path;
src/lib.rs CHANGED
@@ -1,8 +1,3 @@
1
- #[cfg(all(debug_assertions, not(feature = "debug-embed")))]
2
- extern crate walkdir;
3
-
4
- #[cfg(feature = "compression")]
5
- extern crate include_flate;
6
1
  #[cfg(feature = "compression")]
7
2
  #[cfg_attr(feature = "compression", doc(hidden))]
8
3
  pub use include_flate::flate;
tests/interpolated_path.rs CHANGED
@@ -7,17 +7,14 @@ struct Asset;
7
7
 
8
8
  #[test]
9
9
  fn get_works() {
10
- match Asset::get("index.html") {
10
+ if Asset::get("index.html").is_none() {
11
- None => assert!(false, "index.html should exist"),
11
+ panic!("index.html should exist");
12
- _ => assert!(true),
13
12
  }
14
- match Asset::get("gg.html") {
13
+ if Asset::get("gg.html").is_some() {
15
- Some(_) => assert!(false, "gg.html should not exist"),
14
+ panic!("gg.html should not exist");
16
- _ => assert!(true),
17
15
  }
18
- match Asset::get("images/llama.png") {
16
+ if Asset::get("images/llama.png").is_none() {
19
- None => assert!(false, "llama.png should exist"),
17
+ panic!("llama.png should exist");
20
- _ => assert!(true),
21
18
  }
22
19
  }
23
20
 
tests/lib.rs CHANGED
@@ -7,17 +7,14 @@ struct Asset;
7
7
 
8
8
  #[test]
9
9
  fn get_works() {
10
- match Asset::get("index.html") {
10
+ if Asset::get("index.html").is_none() {
11
- None => assert!(false, "index.html should exist"),
11
+ panic!("index.html should exist");
12
- _ => assert!(true),
13
12
  }
14
- match Asset::get("gg.html") {
13
+ if Asset::get("gg.html").is_some() {
15
- Some(_) => assert!(false, "gg.html should not exist"),
14
+ panic!("gg.html should not exist");
16
- _ => assert!(true),
17
15
  }
18
- match Asset::get("images/llama.png") {
16
+ if Asset::get("images/llama.png").is_none() {
19
- None => assert!(false, "llama.png should exist"),
17
+ panic!("llama.png should exist");
20
- _ => assert!(true),
21
18
  }
22
19
  }
23
20
 
utils/Cargo.toml CHANGED
@@ -9,6 +9,7 @@ license = "MIT"
9
9
  keywords = ["http", "rocket", "static", "web", "server"]
10
10
  categories = ["web-programming::http-server"]
11
11
  authors = ["pyros2097 <pyros2097@gmail.com>"]
12
+ edition = "2018"
12
13
 
13
14
  [dependencies]
14
15
  walkdir = "2.2.7"
utils/src/lib.rs CHANGED
@@ -1,6 +1,3 @@
1
- #[cfg(all(debug_assertions, not(feature = "debug-embed")))]
2
- extern crate walkdir;
3
-
4
1
  #[cfg_attr(all(debug_assertions, not(feature = "debug-embed")), allow(unused))]
5
2
  pub struct FileEntry {
6
3
  pub rel_path: String,