rasset

Crates.iorasset
lib.rsrasset
version1.0.0
created_at2025-06-14 05:40:01.139803+00
updated_at2025-06-15 06:50:46.452161+00
descriptionRust Asset Management Library
homepagehttps://github.com/LeviLovie/rasset
repositoryhttps://github.com/LeviLovie/rasset
max_upload_size
id1712128
size27,813
LeviLovie (LeviLovie)

documentation

https://docs.rs/rasset

README

Crates.io Docs.rs License CI

Rust Asset System

Rasset is a library that provides proc macros to serialize Rust structs into a binary file at build time and deserialize at runtime.

Quick start

Please take a look at examples and the template.

asset_def! {
    Sprite: {
        size: (u32, u32),
        texture: String,
    }
}

assets!(
    PlayerSprite: Sprite {
        size: (64, 64),
        texture: "path/to/player_texture.png".to_string(),
    },
    EnemySprite: Sprite {
        size: (32, 32),
        texture: "path/to/enemy_texture.png".to_string(),
    }
);

fn main() -> Result<(), Error> {
    let compiled_assets = compile_assets()?;

    let registry = Registry::builder()
        .reg_type::<Sprite>()
        .load(&compiled_assets)?;

    println!("Loaded registry with {} assets", registry.amount());
    println!("Player: {:?}", registry.get_asset::<Sprite>("PlayerSprite"));
    println!("Enemy: {:?}", registry.get_asset::<Sprite>("EnemySprite"));

    Ok(())
}

Documentation

Asset definiton

Proc macro asset_def creates a struct for the asset type.

Asset declaration

Proc macro assets takes instances of a struct defined in asset_def and creates a compile_assets func.

Proc macro asset_file takes a YAML file and generates assets from there, similar to assets. Example:

- name: Player
  type: Sprite
  metadata:
    size: [64, 64]
    texture: "/path/to/player/texture/"

- name: Enemy
  type: Sprite
  metadata:
    size: [32, 32]
    texture: "/path/to/enemy/texture/"

YAML supports there tags:

  • !Rust: Instead of storing the string, parser with interpret the data as a Rust expression. texture: !Rust include_bytes!("texture.png").to_vec()
  • !IncludeBytes: Generates include_bytes!(STRING).
  • !IncludeStr: Generates include_str!(STRING).
  • !IncludeVec: Generates include_bytes!(STRING).to_vec().
Commit count: 37

cargo fmt