rust_embed

Trait RustEmbed

source
pub trait RustEmbed {
    // Required methods
    fn get(file_path: &str) -> Option<EmbeddedFile>;
    fn iter() -> Filenames ;
}
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::RustEmbed;

#[derive(RustEmbed)]
#[folder = "examples/public/"]
struct Asset;

fn main() {}

Required Methods§

source

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>).

source

fn iter() -> Filenames

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.

Object Safety§

This trait is not object safe.

Implementors§