[Code Review needed] Static asset manager for Rust. Compile-time asset embedding

Hello everyone!

I've been working on a crate that embeds assets directly into your Rust binary at compile time while providing a convenient API to access them. I'd really appreciate some feedback and code review on this project.

Project overview

The core idea is to make working with static assets in Rust projects easier by:

  • Embedding files directly into the binary at compile time
  • Providing strong typing with IDE autocompletion via generated enums
  • Supporting regex-based filtering to include/exclude specific files
  • Removing runtime overhead (no filesystem access or initialization)

The crate provides a simple assets! macro that scans a directory and generates an enum with variants for each asset:

use asset_macros::assets;
use asset_traits::{Asset, AssetCollection};

// Generate asset enums for different directories
assets!(AudioAssets, "assets/audio");
assets!(UiAssets, "assets/ui", include: r"\.(png|jpg|svg)$");
assets!(ConfigAssets, "assets/config", include: r"\.json$", ignore: r"temp");

// You can then access assets with full IDE support
let logo_bytes = UiAssets::LogoPng.bytes();
let logo_path = UiAssets::LogoPng.path();

// Find assets by path
if let Some(config) = ConfigAssets::find_by_path("settings.json") {
    // use config...
}

// Iterate over all assets of a specific type
for asset in UiAssets::all() {
    println!("UI asset: {} ({} bytes)", asset.path(), asset.bytes().len());
}

I'd love feedback on:

  • Does the API make sense? Too much/too little abstraction?
  • Any issues in the macro code?
  • Any weird edge cases I probably missed?
  • Ways to improve the docs

The code is currently in a PR going from the dev branch to main. This is part of my Capstone Project for Rustcamp Winter 2025.

GitHub PR: Rustcamp Winter 2025 Capstone Project: Static Asset Manager by twentyone212121 · Pull Request #1 · twentyone212121/asset-manager · GitHub

The macros crate is about 300 lines of code. I tried to make it concise.

I got the idea for this project from Logan Smith's video about proc macros. Also, I tried to
follow standard compiler architecture (parsing -> intermediate representation -> code generation).

1 Like