~repos /rust-embed
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.
d0336a67
—
AzureMarker 4 years ago
Update documentation with EmbeddedFile changes
- 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
|
-
///
|
|
18
|
+
/// The files in the specified folder will be embedded into the executable in
|
|
19
|
-
///
|
|
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
|
-
///
|
|
33
|
+
/// Get an embedded file and its metadata.
|
|
34
34
|
///
|
|
35
|
-
/// If the feature `debug-embed` is enabled or the binary
|
|
35
|
+
/// If the feature `debug-embed` is enabled or the binary was compiled in
|
|
36
|
-
/// release mode, the
|
|
36
|
+
/// release mode, the file information is embedded in the binary and the file
|
|
37
|
-
/// `Cow::Borrowed(&'static [u8])`
|
|
37
|
+
/// data is returned as a `Cow::Borrowed(&'static [u8])`.
|
|
38
38
|
///
|
|
39
|
-
/// Otherwise, the
|
|
39
|
+
/// Otherwise, the information is read from the file system on each call and
|
|
40
|
-
/// `Cow::Owned(Vec<u8>)`
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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>>>),
|