~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. src/lib.rs +14 -14
src/lib.rs CHANGED
@@ -15,8 +15,9 @@ pub extern crate rust_embed_utils as utils;
15
15
 
16
16
  /// A directory of binary assets.
17
17
  ///
18
- /// They should be embedded into the executable for release builds,
18
+ /// The files in the specified folder will be embedded into the executable in
19
- /// but can be read from the filesystem for debug builds.
19
+ /// release builds. Debug builds will read the data from the file system at
20
+ /// runtime.
20
21
  ///
21
22
  /// This trait is meant to be derived like so:
22
23
  /// ```
@@ -28,39 +29,38 @@ pub extern crate rust_embed_utils as utils;
28
29
  ///
29
30
  /// fn main() {}
30
31
  /// ```
31
-
32
32
  pub trait RustEmbed {
33
- /// Given a relative path from the assets folder, returns the bytes if found.
33
+ /// Get an embedded file and its metadata.
34
34
  ///
35
- /// If the feature `debug-embed` is enabled or the binary is compiled in
35
+ /// If the feature `debug-embed` is enabled or the binary was compiled in
36
- /// release mode, the bytes have been embeded in the binary and a
36
+ /// release mode, the file information is embedded in the binary and the file
37
- /// `Cow::Borrowed(&'static [u8])` is returned.
37
+ /// data is returned as a `Cow::Borrowed(&'static [u8])`.
38
38
  ///
39
- /// Otherwise, the bytes are read from the file system on each call and a
39
+ /// Otherwise, the information is read from the file system on each call and
40
- /// `Cow::Owned(Vec<u8>)` is returned.
40
+ /// the file data is returned as a `Cow::Owned(Vec<u8>)`.
41
41
  fn get(file_path: &str) -> Option<EmbeddedFile>;
42
42
 
43
- /// Iterates the files in this assets folder.
43
+ /// Iterates over the file paths in the folder.
44
44
  ///
45
45
  /// If the feature `debug-embed` is enabled or the binary is compiled in
46
- /// release mode, a static array to the list of relative paths to the files
46
+ /// release mode, a static array containing the list of relative file paths
47
47
  /// is used.
48
48
  ///
49
49
  /// Otherwise, the files are listed from the file system on each call.
50
50
  fn iter() -> Filenames;
51
51
  }
52
52
 
53
- /// An iterator type over filenames.
53
+ /// An iterator over filenames.
54
54
  ///
55
55
  /// This enum exists for optimization purposes, to avoid boxing the iterator in
56
56
  /// some cases. Do not try and match on it, as different variants will exist
57
57
  /// depending on the compilation context.
58
58
  pub enum Filenames {
59
- /// Release builds use a nameable iterator type, which can be stack-allocated.
59
+ /// Release builds use a named iterator type, which can be stack-allocated.
60
60
  #[cfg(any(not(debug_assertions), feature = "debug-embed"))]
61
61
  Embedded(std::slice::Iter<'static, &'static str>),
62
62
 
63
- /// The debug iterator type is currently unnamable and still needs to be
63
+ /// The debug iterator type is currently unnameable and still needs to be
64
64
  /// boxed.
65
65
  #[cfg(all(debug_assertions, not(feature = "debug-embed")))]
66
66
  Dynamic(Box<dyn Iterator<Item = std::borrow::Cow<'static, str>>>),