path2enum
path2enum
is a procedural macro for Rust that generates enums based on your project's real file paths. It enables type-safe, autocomplete-friendly access to static assets and configuration files, reducing errors and improving developer experience.
Features
- Automatically generates enums from file system directories.
- Supports nested directories with intuitive enum variants.
- Provides a
.to_str()
method returning the file path as a string. - Supports filtering by file extension (e.g.,
svg
,toml
). - Uses a unique delimiter (
ノ
) to separate nested directories in enum variant names.
Installation
Add this to your Cargo.toml
:
[]
= "0.1.0"
Usage
Import the magic macro and apply it to an empty enum to automatically generate variants representing files in your project directories. You can optionally specify the directory path (path) and file extension filter (ext).
use magic;