Niklas Kapelle 6a64527022
version bump
now with str and bytes mode
2025-07-28 21:08:53 +02:00
2025-07-28 21:07:27 +02:00
2025-07-28 19:35:48 +02:00
2025-07-28 21:07:27 +02:00
2025-07-28 19:35:48 +02:00
2025-07-28 21:08:53 +02:00
2025-07-28 21:08:53 +02:00
2025-07-28 20:50:54 +02:00

Simple way to use include_bytes! for directories.

Example

You can embed files two ways.

Bytes mode

use dir_embed::Embed;

#[derive(Embed)]
#[dir = "../web/static"] // Path is relativ to the current file
#[mode = "bytes"] // Is the default. Can be omitted.
pub struct Assets;

fn main(){
    let file: &[u8] = Assets::get("css/style.css").expect("Can't find file");

    let string = str::from_utf8(file).expect("Failed to parse file");

    println!("{string}");
}

Str mode

use dir_embed::Embed;

#[derive(Embed)]
#[dir = "../web/static"] // Path is relativ to the current file
#[mode = "str"]
pub struct Assets;

fn main(){
    let file: &str = Assets::get("css/style.css").expect("Can't find file");

    println!("{file}");
}
Description
Like include_bytes! for directories
https://crates.io/crates/dir-embed/
Readme 58 KiB
Languages
Rust 100%