~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 +7 -1
readme.md CHANGED
@@ -72,6 +72,11 @@ If the feature `debug-embed` is enabled or the binary compiled in release mode a
72
72
 
73
73
  Otherwise the files are listed from the file system on each call.
74
74
 
75
+ ## The `prefix` attribute
76
+ You can add `#[prefix = "my_prefix/"]` to the `RustEmbed` struct to add a prefix
77
+ to all of the file paths. This prefix will be required on `get` calls, and will
78
+ be included in the file paths returned by `iter`.
79
+
75
80
  ## Features
76
81
 
77
82
  ### `debug-embed`
@@ -101,10 +106,11 @@ use rust_embed::RustEmbed;
101
106
 
102
107
  #[derive(RustEmbed)]
103
108
  #[folder = "examples/public/"]
109
+ #[prefix = "prefix/"]
104
110
  struct Asset;
105
111
 
106
112
  fn main() {
107
- let index_html = Asset::get("index.html").unwrap();
113
+ let index_html = Asset::get("prefix/index.html").unwrap();
108
114
  println!("{:?}", std::str::from_utf8(index_html.as_ref()));
109
115
 
110
116
  for file in Asset::iter() {