embed-resources

Crates.ioembed-resources
lib.rsembed-resources
version
sourcesrc
created_at2025-01-26 06:24:58.128643
updated_at2025-02-02 21:39:08.842964
descriptionA simple Rust crate to embed resources (files, URLs, data) as byte arrays.
homepage
repositoryhttps://github.com/jzombie/rust-embed-bytes
max_upload_size
id1531104
Cargo.toml error:TOML parse error at line 17, column 1 | 17 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Jeremy Harris (jzombie)

documentation

README

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.

Commit count: 14

cargo fmt