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


ed4b61d7 pyros2097

7 years ago
Merge branch 'master' into fix/tests
.travis.yml CHANGED
@@ -16,4 +16,6 @@ script:
16
16
  - cargo test --test lib
17
17
  - cargo test --test lib --release
18
18
  - cargo build --example basic
19
- - cargo build --release --example basic
19
+ - cargo build --example basic --release
20
+ - cargo build --example actix --features actix
21
+ - cargo build --example actix --features actix --release
Cargo.toml CHANGED
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "rust-embed"
3
- version = "2.0.0"
3
+ version = "3.0.0"
4
4
  description = "Rust Custom Derive Macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev"
5
5
  readme = "readme.md"
6
6
  documentation = "https://docs.rs/rust-embed"
@@ -18,16 +18,15 @@ syn = "0.11"
18
18
  quote = "0.3"
19
19
  walkdir = "2.1.4"
20
20
 
21
+ actix-web = { version = "0.6", optional = true }
22
+
21
23
  rocket = { version = "0.3.6", optional = true }
22
24
  rocket_codegen = { version = "0.3.6", optional = true }
23
25
  rocket_contrib = { version = "0.3.6", optional = true }
24
26
 
25
- [dev-dependencies]
26
- rouille = "2.1.0"
27
- fern = "0.5"
28
-
29
27
  [features]
30
28
  nightly = ["rocket", "rocket_codegen", "rocket_contrib"]
29
+ actix = ["actix-web"]
31
30
 
32
31
  [badges]
33
32
  appveyor = { repository = "pyros2097/rust-embed" }
changelog.md CHANGED
@@ -6,18 +6,89 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
6
6
 
7
7
  Thanks to [Mcat12](https://github.com/Mcat12) for the changelog.
8
8
 
9
+ ## [3.0.0] - 2018-06-01
10
+ ### Changed
11
+ - The derive attribute style so we don't need `attr_literals` and it can be used in stable rust now. Thanks to [Mcat12](https://github.com/Mcat12).
12
+ ```rust
13
+ #[folder("assets/")]
14
+ ```
15
+ to
16
+ ```rust
17
+ #[folder = "assets/"]
18
+ ```
19
+ ### Removed
20
+ - log dependecy as we are not using it anymore
21
+
9
22
  ## [2.0.0] - 2018-05-26
10
23
  ### Changed
11
24
  - Reimplemented the macro for release to use include_bytes for perf sake. Thanks to [lukad](https://github.com/lukad).
12
25
 
13
26
  ## [1.1.1] - 2018-03-19
14
27
  ### Changed
28
+ - Fixed usage error message
29
+
30
+ ## [1.1.0] - 2018-03-19
31
+ ### Added
32
+ - Release mode for custom derive
33
+ ### Changed
34
+ - Fixed tests in travis
35
+
36
+ ## [1.0.0] - 2018-03-18
37
+ ### Changed
15
- - Converted the rust-embed macro `embed!` into a Rust Custom Derive Macro `#[derive(RustEmbed)]`
38
+ - Converted the rust-embed macro `embed!` into a Rust Custom Derive Macro `#[derive(RustEmbed)]` which implements get on the struct
39
+ ```rust
40
+ let asset = embed!("examples/public/")
41
+ ```
42
+ to
43
+ ```rust
44
+ #[derive(RustEmbed)]
45
+ #[folder = "examples/public/"]
46
+ struct Asset;
47
+ ```
48
+
49
+ ## [0.5.2] - 2018-03-16
50
+ ### Added
51
+ - rouille example
52
+
53
+ ## [0.5.1] - 2018-03-16
54
+ ### Removed
55
+ - the plugin attribute from crate
16
56
 
17
57
  ## [0.5.0] - 2018-03-16
58
+ ### Added
59
+ - rocket example
18
60
  ### Changed
19
61
  - Converted the rust-embed executable into a macro `embed!` which now loads files at compile time during release and from the fs during dev.
20
62
 
63
+ ## [0.4.0] - 2017-03-2
64
+ ### Changed
65
+ - `generate_assets` to public again
66
+
67
+ ## [0.3.5] - 2017-03-2
68
+ ### Added
69
+ - rust-embed prefix to all logs
70
+
71
+ ## [0.3.4] - 2017-03-2
72
+ ### Changed
73
+ - the lib to be plugin again
74
+
75
+ ## [0.3.3] - 2017-03-2
76
+ ### Changed
77
+ - the lib to be proc-macro from plugin
78
+
79
+ ## [0.3.2] - 2017-03-2
80
+ ### Changed
81
+ - lib name from `rust-embed` to `rust_embed`
82
+
83
+ ## [0.3.1] - 2017-03-2
84
+ ### Removed
85
+ - hyper example
86
+
87
+ ## [0.3.0] - 2017-02-26
88
+ ### Added
89
+ - rust-embed executable which generates rust code to embed resource files into your rust executable
90
+ it creates a file like assets.rs that contains the code for your assets.
91
+
21
92
  ## [0.2.0] - 2017-03-16
22
93
  ### Added
23
94
  - rust-embed executable which generates rust code to embed resource files into your rust executable
examples/actix.rs ADDED
@@ -0,0 +1,13 @@
1
+ extern crate actix_web;
2
+ use actix_web::{server, App, HttpRequest};
3
+
4
+ fn index(_req: HttpRequest) -> &'static str {
5
+ "Hello world!"
6
+ }
7
+
8
+ fn main() {
9
+ server::new(|| App::new().resource("/", |r| r.f(index)))
10
+ .bind("127.0.0.1:8000")
11
+ .unwrap()
12
+ .run();
13
+ }
examples/public/images/flower.jpg ADDED
Binary file
examples/rouille.rs DELETED
@@ -1,20 +0,0 @@
1
- extern crate rouille;
2
-
3
- use rouille::Response;
4
-
5
- // TBD
6
- fn main() {
7
- println!("Now listening on localhost:8000");
8
- rouille::start_server("localhost:8000", move |request| {
9
- {
10
- let response = rouille::match_assets(&request, ".");
11
- if response.is_success() {
12
- return response;
13
- }
14
- }
15
- Response::html(
16
- "404 error. Try <a href=\"/README.md\"`>README.md</a> or \
17
- <a href=\"/src/lib.rs\">src/lib.rs</a> for example.",
18
- ).with_status_code(404)
19
- });
20
- }
readme.md CHANGED
@@ -3,11 +3,17 @@ Rust Custom Derive Macro which loads files into the rust binary at compile time
3
3
 
4
4
  You can use this to embed your css, js and images into a single executable which can be deployed to your servers. Also it makes it easy to build a very small docker image for you to deploy.
5
5
 
6
+ ### Dev
7
+ <img src="https://user-images.githubusercontent.com/1687946/40840773-b1ae1ce6-65c5-11e8-80ac-9e9196701ca2.png" width="700" height="100">
8
+
9
+ ### Release
10
+ <img src="https://user-images.githubusercontent.com/1687946/40840774-b1dd709a-65c5-11e8-858d-73a88e25f07a.png" width="700" height="184">
11
+
6
12
  ## Installation
7
13
 
8
14
  ```
9
15
  [dependencies]
10
- rust-embed="2.0.0"
16
+ rust-embed="3.0.0"
11
17
  ```
12
18
 
13
19
  ## Documentation
@@ -42,14 +48,18 @@ To run the example in release mode where it reads from binary,
42
48
 
43
49
  `cargo run --release --example basic`
44
50
 
51
+ Note: To run the `actix-web` example:
52
+
53
+ `cargo run --example actix --features actix`
54
+
45
55
  Note: To run the `rocket` example, add the `nightly` feature flag and run on a nightly build:
46
56
 
47
57
  `cargo +nightly run --example rocket --features nightly`
48
58
 
49
59
  ## Testing
50
- debug: `cargo test --tests --lib`
60
+ debug: `cargo test --test lib`
51
61
 
52
- release: `cargo test --tests --lib --release`
62
+ release: `cargo test --release --test lib`
53
63
 
54
64
  Go Rusketeers!
55
65
  The power is yours!
src/lib.rs CHANGED
@@ -53,7 +53,7 @@ fn generate_assets(ident: &syn::Ident, folder_path: String) -> quote::Tokens {
53
53
  .filter_map(|e| e.ok())
54
54
  .filter(|e| e.file_type().is_file())
55
55
  {
56
- println!(" \x1b[92mCompiling\x1b[0m {}", entry.path().display());
56
+ println!(" \x1b[1m\x1b[92mCompiling\x1b[0m {}", entry.path().display());
57
57
  let base = &folder_path.clone();
58
58
  let key = String::from(entry.path().to_str().expect("Path does not have a string representation")).replace(base, "");
59
59
  let canonical_path = std::fs::canonicalize(entry.path()).expect("Could not get canonical path");
@@ -110,7 +110,7 @@ fn impl_rust_embed(ast: &syn::DeriveInput) -> Tokens {
110
110
  panic!("#[derive(RustEmbed)] attribute value must be a string literal");
111
111
  }
112
112
  };
113
- println!("folder: {}", folder_path);
113
+ println!(" \x1b[1m\x1b[92mCompiling\x1b[0m {}", folder_path);
114
114
  generate_assets(ident, folder_path)
115
115
  }
116
116