#resources #embed #data #url #byte #path #container

embed-resources

A simple Rust crate to embed resources (files, URLs, data) as byte arrays

4 releases

new 0.1.0-alpha3 Jan 29, 2025
0.1.0-alpha2 Jan 26, 2025

#31 in #embed

Download history 340/week @ 2025-01-23

349 downloads per month
Used in ticker-sniffer

MIT license

25KB
171 lines

embed-resources (Work in Progress)

embed-resources is a Rust crate built on top of embed-bytes that extends its functionality to handle multiple resource types: local files, URLs, and in-memory data. It also supports optional Gzipped compression for reduced storage size.

Unlike embed-bytes, which directly embeds assets, embed-resources simplifies managing mixed resources by organizing them in a virtual "container." Resources are automatically converted into .bin files, and a Rust source file is generated to embed them using include_bytes!.

Key Features:

  • Multi-Type Resource Support: Embed local files, fetch remote data, or embed arbitrary in-memory data.
  • Optional Compression: Compress resources with Gzipped encoding during the build process.
  • Unified Management: Organize resources into a container with minimal setup while benefiting from zero-cost runtime embedding.

Example Usage:

In build.rs:

use embed_resources::{Resource, ResourceContainer};
use std::path::Path;

fn main() -> std::io::Result<()> {
    let mut container = ResourceContainer::new(Path::new("embed"));

    container.add_resource("local_file", Resource::File("assets/file.txt".to_string()), true);
    container.add_resource("remote_data", Resource::Url("https://example.com/data.bin".to_string()), true);
    container.add_resource("in_memory_data", Resource::Data(bytes::Bytes::from("Hello, world!")), true);

    container.embed_all()?;

    Ok(())
}

This creates .bin files and a Rust source file in the embed/ directory, ready to use with include_bytes!.

License

MIT License (c) 2025 Jeremy Harris.

Dependencies

~4–15MB
~193K SLoC