Crates.io | enum_builder |
lib.rs | enum_builder |
version | 0.1.6 |
created_at | 2025-07-05 10:54:35.47831+00 |
updated_at | 2025-07-05 17:46:28.696623+00 |
description | Simple macros that allow building enum types from variants that can be defined in multiple dispersed files in the crate. |
homepage | https://github.com/garfunkel/enum_builder |
repository | https://github.com/garfunkel/enum_builder |
max_upload_size | |
id | 1738956 |
size | 17,823 |
Simple macros that allow building enum types from variants that can be defined in multiple dispersed files in the crate.
mod animals;
use animals::*;
#[enum_builder]
enum Animal {}
// expanded result
// enum Animal {
// Dog(Dog),
// Cow(Cow),
// Fish(Fish),
// }
#[enum_builder_variant(Animal)]
struct Dog {}
#[enum_builder_variant(Animal)]
struct Cow {}
#[enum_builder_variant(Animal)]
struct Fish {}
It can be very useful to combine this crate with the enum_dispatch crate, to allow for a simple "plugin" architecture without the overhead of dynamic dispatch. When doing this, take care to note that the order of macros is important, as enum_builder must be used before enum_dispatch.
#[enum_builder]
#[enum_dispatch]
enum Animal {}