~repos /rust-embed

#rust#proc-macro#http

git clone https://pyrossh.dev/repos/rust-embed.git
Discussions: https://groups.google.com/g/rust-embed-devs

rust macro which loads files into the rust binary at compile time during release and loads the file from the fs during dev.


Files changed (4) hide show
  1. Cargo.toml +2 -2
  2. changelog.md +8 -1
  3. impl/Cargo.toml +1 -1
  4. readme.md +18 -7
Cargo.toml CHANGED
@@ -33,8 +33,8 @@ required-features = ["interpolate-folder-path"]
33
33
 
34
34
  [dependencies]
35
35
  walkdir = "2.3.1"
36
- rust-embed-impl = { version = "5.9.0", path = "impl"}
36
+ rust-embed-impl = { version = "6.0.0", path = "impl"}
37
- rust-embed-utils = { version = "5.1.0", path = "utils"}
37
+ rust-embed-utils = { version = "6.0.0", path = "utils"}
38
38
 
39
39
  include-flate = { version = "0.1", optional = true, features = ["stable"] }
40
40
  actix-web = { version = "3", default-features = false, optional = true }
changelog.md CHANGED
@@ -5,7 +5,14 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
6
6
  and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
7
7
 
8
- Thanks to [Mcat12](https://github.com/Mcat12) for the changelog.
8
+ Thanks to [Mark Drobnak](https://github.com/AzureMarker) for the changelog.
9
+
10
+ ## [6.0.0] - 2021-08-01
11
+
12
+ Idea came about from [Cody Casterline](https://github.com/NfNitLoop)
13
+
14
+ - Breaking change the `Asset::get()` api has changed and now returns an `EmbeddedFile` which contains a `data` field which is the bytes of the file and
15
+ a `metadata` field which has theses 2 properties associated to the file `hash` and `last_modified`;
9
16
 
10
17
  ## [5.9.0] - 2021-01-18
11
18
 
impl/Cargo.toml CHANGED
@@ -15,7 +15,7 @@ edition = "2018"
15
15
  proc-macro = true
16
16
 
17
17
  [dependencies]
18
- rust-embed-utils = { version = "5.0.0", path = "../utils"}
18
+ rust-embed-utils = { version = "6.0.0", path = "../utils"}
19
19
 
20
20
  syn = "1"
21
21
  quote = "1"
readme.md CHANGED
@@ -30,7 +30,7 @@ The macro will generate the following code:
30
30
 
31
31
  ```rust
32
32
  impl Asset {
33
- pub fn get(file_path: &str) -> Option<Cow<'static, [u8]>> {
33
+ pub fn get(file_path: &str) -> Option<rust_embed::EmbeddedFile> {
34
34
  ...
35
35
  }
36
36
 
@@ -39,22 +39,32 @@ impl Asset {
39
39
  }
40
40
  }
41
41
  impl RustEmbed for Asset {
42
- fn get(file_path: &str) -> Option<Cow<'static, [u8]>> {
42
+ fn get(file_path: &str) -> Option<rust_embed::EmbeddedFile> {
43
43
  ...
44
44
  }
45
45
  fn iter() -> impl Iterator<Item = Cow<'static, str>> {
46
46
  ...
47
47
  }
48
48
  }
49
+
50
+ // Where EmbeddedFile contains these fields,
51
+ pub struct EmbeddedFile {
52
+ pub data: Cow<'static, [u8]>,
53
+ pub metadata: Metadata,
54
+ }
55
+ pub struct Metadata {
56
+ hash: [u8; 32],
57
+ last_modified: Option<u64>,
58
+ }
49
59
  ```
50
60
 
51
- ### `get(file_path: &str)`
61
+ ### `get(file_path: &str) -> Option<rust_embed::EmbeddedFile>`
52
62
 
53
- Given a relative path from the assets folder returns the bytes if found.
63
+ Given a relative path from the assets folder returns the `EmbeddedFile` if found.
54
64
 
55
- If the feature `debug-embed` is enabled or the binary compiled in release mode the bytes have been embeded in the binary and a `Cow::Borrowed(&'static [u8])` is returned.
65
+ If the feature `debug-embed` is enabled or the binary compiled in release mode the bytes have been embeded in the binary and a `Option<rust_embed::EmbeddedFile>` is returned.
56
66
 
57
- Otherwise the bytes are read from the file system on each call and a `Cow::Owned(Vec<u8>)` is returned.
67
+ Otherwise the bytes are read from the file system on each call and a `Option<rust_embed::EmbeddedFile>` is returned.
58
68
 
59
69
  ### `iter()`
60
70
 
@@ -65,6 +75,7 @@ If the feature `debug-embed` is enabled or the binary compiled in release mode a
65
75
  Otherwise the files are listed from the file system on each call.
66
76
 
67
77
  ## The `prefix` attribute
78
+
68
79
  You can add `#[prefix = "my_prefix/"]` to the `RustEmbed` struct to add a prefix
69
80
  to all of the file paths. This prefix will be required on `get` calls, and will
70
81
  be included in the file paths returned by `iter`.
@@ -103,7 +114,7 @@ struct Asset;
103
114
 
104
115
  fn main() {
105
116
  let index_html = Asset::get("prefix/index.html").unwrap();
106
- println!("{:?}", std::str::from_utf8(index_html.as_ref()));
117
+ println!("{:?}", std::str::from_utf8(index_html.data.as_ref()));
107
118
 
108
119
  for file in Asset::iter() {
109
120
  println!("{}", file.as_ref());