Simple rust asset handling derive macro for enums, and a proc-macro learning resource!

Overview

asset-derive

Docs Crate License TODOs

SummaryTodosDocs


Summary

Simple Rust asset loading derive macro for Enums, and a resource for learning proc-macros!

Please feel free to offer any advice or create a pull request.

The original intent of this library was for compile time loading assets into a binary. This will eventually allow for run-time loading as well, but as for now that will be a future expansion.

TODOs

List of ideas I have at the moment for this project's expansion. Please create an issue for a new item to add to this list, using todo label.

  • Filename prefix
  • Run-time Loading
    • Static (Once on init)
    • Dynamic (Fluid loading)
  • Compile-time Loading

Structure

Since asset-derive is meant to be a procedural macro crate, while also housing a trait implementation as well (to be derived), there is a somewhat complex project structue. This is because of the current annoyance of proc-macro crates having to be defined completely separate to normal crates.

The external API shall stay the same fortunately, asset-derive will now be stuck as the trait implementation crate which depends on asset-derive-macro which houses the actual macro implementation. This is unavoidable for the time being, but I did the best I could to not have the external API change and make it as simple as can be.

Code Tree

asset-derive/       <-- Crate to use (trait implementation)
    src/
    examples/       <-- Houses examples using the trait and macro itself.
    asset-derive/   <-- Actual internal derive macro crate. Will be pulled in by main crate.
        src/

Example

use asset_derive::Asset;

#[derive(Asset)]
#[asset(basepath = "./icons/", ext = "svg")]
enum Icon {
    #[asset(ext = "png")]
    Select,
    Folder,
    #[asset(filename = "folder-dim")]
    FolderDim,
}

Icon::Select.fetch()
Icon::FolderDim.fetch_static()
Comments
  • Static Fetching

    Static Fetching

    Summary

    At the moment fetching is currently forced into a Vec<u8>. This was for easy portability into having dynamic loading in the future, and to not change the API later.

    It would be nice to have the ability to actually fetch it as a constant &'static [u8] and since it is loaded at compile-time that is totally possible. Since the future will have dynamic loading though as well, the API will be Option<&'static [u8]> where Some(T) will be for all compile-time loaded variants that actually have a static lifetime and None will be returned for the other cases.

    enhancement todo 
    opened by Shadorain 1
  • `Asset` Trait

    `Asset` Trait

    Summary

    Currently, Asset doesn't implement a trait on the type being derived on. This is necessary to have for type portability (trait objects, trait bounds, etc).

    The internal structure has to shift a little bit, but the main API will remain the same. the Asset trait will be both derivable with the macro still and can be manually derived as well if so desired.

    As for implementation of this... getters should stay in the main enum's impl, but the fetch method should maybe be moved to the trait? I have ideas for a custom loading setup for the future, so I have to figure out what fit's best here.

    I'm all ears as always.

    enhancement todo 
    opened by Shadorain 1
  • feat(#7): Static Fetching

    feat(#7): Static Fetching

    Summary

    Added static fetching of resources via a new Asset trait method fetch_static which will return an Option<&'static [u8]> when called on an Asset derived type.

    opened by Shadorain 0
  • feat: Asset trait added, crate structure redone.

    feat: Asset trait added, crate structure redone.

    This feature is somewhat larger, crate is now 0.1.3.

    Firstly, the entire repo had to be restructured because proc-macro crates with cargo are a genuine pain to work with so 2 crates at minimum are required to be able to use them effectively.

    This all being said... here is what was changed/added:

    • #4 : Asset Trait added.
    • Licenses moved from GPL-3 to a dual license of MIT and Apache-2
    • Repo restructured to house 2 crates.
    • Crate added for internal macro.
    bug documentation enhancement 
    opened by Shadorain 0
  • Struct Support

    Struct Support

    Summary

    Add asset-derive support to Struct data types as well instead of only enums.

    Idea

    I realized with the trait addition #4 , it made having struct's being asset's themselves quite simple. Simply derive the Asset trait on it and the struct itself will have its own filename and asset to fetch. It is limitted to just one asset (unless we do fields in the future too) but it wouldn't be restricting to just enums.

    enhancement todo 
    opened by Shadorain 0
  • Prefix Attribute

    Prefix Attribute

    Summary

    Add an attribute for prefixing all variant filenames.

    Idea

    Currently, Variant names are just lowercased and used as the filename. You can always specify a filename too on a Variant, but what if you want all filenames to be prefixed, maybe by a random string, maybe by the enum name, up to you.

    use asset_derive::Asset;
    
    #[derive(Asset)]
    #[asset(prefix = "icon-")] // <-- Default for this enum, all filenames will be prefixed with `icon-`.
    enum Icon {
        Select,
        Folder,
        #[asset(prefix = "icon-dim-")] // <-- This Variant will override the default prefix for itself.
        FolderDim,
    }
    

    Conclusion

    It isn't that useful of a feature, but it definitely is an idea and something that could be added.

    enhancement todo 
    opened by Shadorain 0
  • Runtime Loading

    Runtime Loading

    Summary

    Add support for loading assets at runtime instead of just compile time (in the binary).

    Idea

    I believe this should be quite simple to implement once compile time loading is fully fleshed out. I have an idea for some sub-attributes that would work for this and they would generate a function load() that will handle the loading.

    use asset_derive::Asset;
    
    #[derive(Asset)]
    #[asset(load = "static")] // <-- Default for this enum
    enum Icon {
        Select,
        Folder,
        #[asset(load = "dynamic")] // <-- This Variant will not be loaded in at compile time, but will get a function to load in at runtime...
        FolderDim,
    }
    

    Conclusion

    Still more to flesh out, but this sounds solid enough and shouldn't be too difficult to implement.

    enhancement todo 
    opened by Shadorain 0
Owner
Shadorain
Shadorain
Bevy plugin helping with asset loading and organisation

Bevy asset loader This Bevy plugin reduces boilerplate when loading game assets. The crate offers the AssetCollection trait and can automatically load

Niklas Eicker 205 Jan 2, 2023
An asset that provides 2d collision detector and kinematics, build from scratch in bevy

Busturi A physics engine An asset that provides 2d collision detector and kinematics, build from scratch in bevy How to use Add PhysicsPlugin to the p

NemuiSen 2 Jun 22, 2022
A Minecraft Java Edition to Bedrock Edition resource pack convertor in Rust

j2be A Minecraft Java Edition to Bedrock Edition resource pack convertor in Rust How to use Note: This project is still in development Run cargo build

Cqdet 11 Sep 15, 2021
Shred - Shared resource dispatcher

shred - Shared resource dispatcher This library allows to dispatch systems, which can have interdependencies, shared and exclusive resource access, in

Amethyst Foundation 206 Nov 21, 2022
Easier joystick, mouse and keyboard input handling in Bevy

ezinput A powerful input-agnostic library targeting complete support to axis and button handling for the Bevy game engine. Table of contents About Bra

Pedro Henrique 31 Dec 20, 2022
A 2d top-down shooter written in Bevy, capable of handling 100K enemies

Bevy 2D Shooter This is a 2d top-down shooter written in Rust using the Bevy game engine. It's capable of handling 100K enemies and uses a kd-tree to

Bones-ai 41 Jul 21, 2024
Rust-and-opengl-lessons - Collection of example code for learning OpenGL in Rust

rust-and-opengl-lessons Project requires Rust 1.31 Collection of example code for learning OpenGL in Rust 00 - Setup 01 - Window 02 - OpenGL Context 0

Nerijus Arlauskas 348 Dec 11, 2022
🦀 my exploration and learning journey with Rust

?? Rust Tutorials Welcome to a repository of my exploration of Rust, using the "The Rust Programming Language" tutorial book! This repo is partially f

nareh agazaryan 1 Jan 9, 2022
Controls the RGB on the keyboard for the Legion 5 Pro from Lenovo. Mostly used for learning a bit of rust.

L5P Keyboard RGB Control Program A fun little experiment. Probably contains bugs. ⚠️ Use at your own risk, the developer is not responsible for any da

null 114 Jan 2, 2023
This is the repository with the tutorials of Learning Rust series in @Leticia-maria Youtube channel

Rust Tutorials This repository contains the information of Learning Rust playlist in my youtube channel. Learning Rust(part. 1)! Installation on Ubunt

Letícia Maria Pequeno Madureira 10 May 24, 2022
My first Real-Time 3D Game Engine learning project written in Rust.

EyeEngine-Rust FOA, sry for my poor English. What is Eye Engine? Eye Engine is my first Real-Time 3D Game Engine learning project. There are two editi

F-seeeye 4 Jan 5, 2022
Learning rust with the olc Pixel Game Engine.

olc rust sketches Learning Rust with the olc Pixel Game Engine. This project is based on olcPixelGameEngine-rs, a Rust API by Ivan Sadikov for the olc

Steve Ruiz 10 Oct 24, 2022
Rust-based command-line language-learning game. Uses the Tatoeba database.

minicloze A command-line language learning game using Tatoeba's great database. Accelerate your studies by putting your knowledge to the test in an ad

benman 3 Mar 5, 2023
This library implements the flip-flop operator from Perl and Ruby as a Rust macro.

flip_flop.rs This library implements the flip-flop operator from Perl and Ruby as a Rust macro. Changelog April 1, 2024: Version 1.0.0. Usage The flip

Utkarsh Kukreti 7 Apr 4, 2024
Self Study on developing a game engine using wgpu as the rendering API. Learning as I go.

Fabled Engine Any issues, enhancement, features, or bugs report are always welcome in Issues. The obj branch is where frequent development and up to d

Khalid 20 Jan 5, 2023
A convenient on-screen message print macro for bevy.

Bevy Debug Text Overlay A proof of concept for adding a very convenient text overlay macro to the bevy game engine. This is derived from the code I us

Nicola Papale 15 Oct 8, 2022
Victorem - easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust.

Victorem Easy UDP game server and client framework for creating simple 2D and 3D online game prototype in Rust. Example Cargo.toml [dependencies] vict

Victor Winbringer 27 Jan 7, 2023
minesweeper-rs is a simple minesweeper game using Rust and windows-rs.

minesweeper-rs minesweeper-rs is a simple minesweeper game using Rust and windows-rs. Key Features TBA Quick Start TBA How To Contribute Contributions

Chris Ohk 15 Jun 25, 2022
A simple Rust and WebAssembly example implementing the Game of Life

rust-wasm-game-of-life rust-wasm-game-of-life is a simple Rust and WebAssembly example implementing the Game of Life based on Rust and WebAssembly boo

Chris Ohk 14 Nov 24, 2021