~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.
1626073e
—
Bernardo 7 years ago
bump minor version and complete readme
- Cargo.toml +2 -2
- impl/Cargo.toml +1 -1
- readme.md +20 -3
Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "rust-embed"
|
|
3
|
-
version = "4.
|
|
3
|
+
version = "4.1.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"
|
|
@@ -12,7 +12,7 @@ authors = ["pyros2097 <pyros2097@gmail.com>"]
|
|
|
12
12
|
|
|
13
13
|
[dependencies]
|
|
14
14
|
walkdir = "2.1.4"
|
|
15
|
-
rust-embed-impl = { version = "4.
|
|
15
|
+
rust-embed-impl = { version = "4.1.0", path = "impl"}
|
|
16
16
|
|
|
17
17
|
actix-web = { version = "0.7", optional = true }
|
|
18
18
|
mime_guess = { version = "2.0.0-alpha.6", optional = true }
|
impl/Cargo.toml
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "rust-embed-impl"
|
|
3
|
-
version = "4.
|
|
3
|
+
version = "4.1.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"
|
readme.md
CHANGED
|
@@ -13,11 +13,18 @@ You can use this to embed your css, js and images into a single executable which
|
|
|
13
13
|
|
|
14
14
|
```
|
|
15
15
|
[dependencies]
|
|
16
|
-
rust-embed="4.
|
|
16
|
+
rust-embed="4.1.0"
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Documentation
|
|
20
|
+
|
|
20
21
|
You need to add the custom derive macro RustEmbed to your struct with an attribute `folder` which is the path to your static folder.
|
|
22
|
+
|
|
23
|
+
The path resolution works as follows:
|
|
24
|
+
|
|
25
|
+
- In `debug` and when `debug-embed` feature is not enabled, the folder path is resolved relative to where the binary is run from.
|
|
26
|
+
- In `release` or when `debug-embed` feature is enabled, the folder path is resolved relative to where `Cargo.toml` is.
|
|
27
|
+
|
|
21
28
|
```rust
|
|
22
29
|
#[derive(RustEmbed)]
|
|
23
30
|
#[folder = "examples/public/"]
|
|
@@ -43,7 +50,7 @@ impl Asset {
|
|
|
43
50
|
|
|
44
51
|
Given a relative path from the assets folder returns the bytes if found.
|
|
45
52
|
|
|
46
|
-
If the feature
|
|
53
|
+
If the feature `debug-embed` is enabled or the binary compiled in release mode the bytes have been embeded in the binary and a `&'static [u8]` is returned.
|
|
47
54
|
|
|
48
55
|
Otherwise the bytes are read from the file system on each call and a `Vec<u8>` is returned.
|
|
49
56
|
|
|
@@ -52,10 +59,16 @@ Otherwise the bytes are read from the file system on each call and a `Vec<u8>` i
|
|
|
52
59
|
|
|
53
60
|
Iterates the files in this assets folder.
|
|
54
61
|
|
|
55
|
-
If the feature
|
|
62
|
+
If the feature `debug-embed` is enabled or the binary compiled in release mode a static array to the list of relative paths to the files is returned.
|
|
56
63
|
|
|
57
64
|
Otherwise the files are listed from the file system on each call.
|
|
58
65
|
|
|
66
|
+
## Features
|
|
67
|
+
|
|
68
|
+
### `debug-embed`
|
|
69
|
+
|
|
70
|
+
Always embed the files in the binary, even in debug mode.
|
|
71
|
+
|
|
59
72
|
|
|
60
73
|
## Usage
|
|
61
74
|
```rust
|
|
@@ -69,6 +82,10 @@ struct Asset;
|
|
|
69
82
|
fn main() {
|
|
70
83
|
let index_html = Asset::get("index.html").unwrap();
|
|
71
84
|
println!("{:?}", std::str::from_utf8(index_html.as_ref()));
|
|
85
|
+
|
|
86
|
+
for file in Asset::iter() {
|
|
87
|
+
println!("{}", file.as_ref());
|
|
88
|
+
}
|
|
72
89
|
}
|
|
73
90
|
```
|
|
74
91
|
|