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


6e11b751 Bernardo

7 years ago
update readme
Files changed (1) hide show
  1. readme.md +31 -2
readme.md CHANGED
@@ -23,11 +23,40 @@ You need to add the custom derive macro RustEmbed to your struct with an attribu
23
23
  #[folder = "examples/public/"]
24
24
  struct Asset;
25
25
  ```
26
- This macro adds a single static method `get` to your type. This method allows you to get your assets from the fs during dev and from the binary during release. It takes the file path as string and returns an `Option` with the bytes.
26
+
27
+
28
+ The macro will generate the following code:
29
+
27
30
  ```rust
31
+ impl Asset {
28
- pub fn get(file_path: &str) -> Option<impl AsRef<[u8]>>
32
+ pub fn get(file_path: &str) -> Option<impl AsRef<[u8]>> {
33
+ ...
34
+ }
35
+
36
+ pub fn iter() -> impl Iterator<Item = impl AsRef<str>> {
37
+ ...
38
+ }
39
+ }
29
40
  ```
30
41
 
42
+ ### `get(file_path: &str)`
43
+
44
+ Given a relative path from the assets folder returns the bytes if found.
45
+
46
+ 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
+
48
+ Otherwise the bytes are read from the file system on each call and a `Vec<u8>` is returned.
49
+
50
+
51
+ ### `iter()`
52
+
53
+ Iterates the files in this assets folder.
54
+
55
+ 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
+
57
+ Otherwise the files are listed from the file system on each call.
58
+
59
+
31
60
  ## Usage
32
61
  ```rust
33
62
  #[macro_use]