~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 (1) hide show
  1. README.md +9 -16
README.md CHANGED
@@ -59,35 +59,32 @@ pub struct Metadata {
59
59
  }
60
60
  ```
61
61
 
62
+ ## Methods
62
- ### `get(file_path: &str) -> Option<rust_embed::EmbeddedFile>`
63
+ * `get(file_path: &str) -> Option<rust_embed::EmbeddedFile>`
63
64
 
64
65
  Given a relative path from the assets folder returns the `EmbeddedFile` if found.
65
-
66
66
  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.
67
-
68
67
  Otherwise the bytes are read from the file system on each call and a `Option<rust_embed::EmbeddedFile>` is returned.
69
68
 
70
- ### `iter()`
69
+ * `iter()`
71
70
 
72
71
  Iterates the files in this assets folder.
73
-
74
72
  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.
75
-
76
73
  Otherwise the files are listed from the file system on each call.
77
74
 
78
75
  ## Attributes
79
- `prefix`
76
+ * `prefix`
80
77
 
81
78
  You can add `#[prefix = "my_prefix/"]` to the `RustEmbed` struct to add a prefix
82
79
  to all of the file paths. This prefix will be required on `get` calls, and will
83
80
  be included in the file paths returned by `iter`.
84
81
 
85
- `metadata_only`
82
+ * `metadata_only`
86
83
 
87
84
  You can add `#[metadata_only = true]` to the `RustEmbed` struct to exclude file contents from the
88
85
  binary. Only file paths and metadata will be embedded.
89
86
 
90
- `allow_missing`
87
+ * `allow_missing`
91
88
 
92
89
  You can add `#[allow_missing = true]` to the `RustEmbed` struct to allow the embedded folder to be missing.
93
90
  In that case, RustEmbed will be empty.
@@ -95,16 +92,14 @@ In that case, RustEmbed will be empty.
95
92
  ## Features
96
93
 
97
94
  * `debug-embed`: Always embed the files in the binary, even in debug mode.
95
+ * `compression`: Compress each file when embedding into the binary. Compression is done via [include-flate](https://crates.io/crates/include-flate).
96
+ * `deterministic-timestamps`: Overwrite embedded files' timestamps with `0` to preserve deterministic builds with `debug-embed` or release mode.
98
- * `interpolate-folder-path`: Allow environment variables to be used in the `folder` path.
97
+ * `interpolate-folder-path`: Allow environment variables to be used in the `folder` path. This will pull the `foo` directory relative to your `Cargo.toml` file.
99
98
  ```rust
100
99
  #[derive(Embed)]
101
100
  #[folder = "$CARGO_MANIFEST_DIR/foo"]
102
101
  struct Asset;
103
102
  ```
104
- This will pull the `foo` directory relative to your `Cargo.toml` file.
105
-
106
- * `compression`: Compress each file when embedding into the binary. Compression is done via [include-flate](https://crates.io/crates/include-flate).
107
-
108
103
  * `include-exclude`: Filter files to be embedded with multiple `#[include = "*.txt"]` and `#[exclude = "*.jpg"]` attributes.
109
104
  Matching is done on relative file paths, via [globset](https://crates.io/crates/globset). `exclude` attributes have higher priority than `include` attributes.
110
105
  ```rust
@@ -118,8 +113,6 @@ use rust_embed::Embed;
118
113
  struct Asset;
119
114
  ```
120
115
 
121
- * `deterministic-timestamps`: Overwrite embedded files' timestamps with `0` to preserve deterministic builds with `debug-embed` or release mode
122
-
123
116
  ## Usage
124
117
 
125
118
  ```rust