includediras_map

A procedural macro which embeds files from a directory as a hashmap in the rust binary. This can be used to embed assets such as images, html, css, and js.

include_dir_as_map extends include_str!() and include_bytes!() and is similar to include_dir.

Usage

Quickstart

Include the following section in Cargo.toml:

toml [dependencies] include_dir_as_map="1"

In your rust code, include the following:

```rust // DirMap is simply an alias for HashMap> use includedirasmap::{includedirasmap, DirMap};

let dirmap: DirMap = includedirasmap!("$CARGOMANIFEST_DIR"); let bytes = dirmap.get("Cargo.toml")?; ```

All paths are relative to the embedded directory, so if root contains files root/foo.txt and root/next/bar.txt, then include_dir_as_map!("root") will result in a hashmap with keys foo.txt and next/bar.txt.

Examples

See the examples/ directory for more examples:

Development

Building

To build the library and examples:

sh cargo build --workspace

Testing

To test the library and procedural macro:

sh cargo test --workspace