pub trait RustEmbed {
// Required methods
fn get(file_path: &str) -> Option<EmbeddedFile>;
fn iter() -> impl Iterator<Item = Cow<'static, str>> + 'static;
}Expand description
A directory of binary assets.
The files in the specified folder will be embedded into the executable in release builds. Debug builds will read the data from the file system at runtime.
This trait is meant to be derived like so:
use rust_embed::Embed;
#[derive(Embed)]
#[folder = "examples/public/"]
struct Asset;
fn main() {}Required Methods§
Sourcefn get(file_path: &str) -> Option<EmbeddedFile>
fn get(file_path: &str) -> Option<EmbeddedFile>
Get an embedded file and its metadata.
If the feature debug-embed is enabled or the binary was compiled in
release mode, the file information is embedded in the binary and the file
data is returned as a Cow::Borrowed(&'static [u8]).
Otherwise, the information is read from the file system on each call and
the file data is returned as a Cow::Owned(Vec<u8>).
Sourcefn iter() -> impl Iterator<Item = Cow<'static, str>> + 'static
fn iter() -> impl Iterator<Item = Cow<'static, str>> + 'static
Iterates over the file paths in the folder.
If the feature debug-embed is enabled or the binary is compiled in
release mode, a static array containing the list of relative file paths
is used.
Otherwise, the files are listed from the file system on each call.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.