Skip to content

Simple macros that allow building enum types from variants that can be defined in multiple dispersed files in the crate.

License

Notifications You must be signed in to change notification settings

garfunkel/enum_builder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

enum_builder

Simple macros that allow building enum types from variants that can be defined in multiple dispersed files in the crate.

Crates.io Documentation License GitHub

Example

main.rs

mod animals;

use animals::*;

#[enum_builder]
enum Animal {}

// expanded result
// enum Animal {
//     Dog(Dog),
//     Cow(Cow),
//     Fish(Fish),
// }

animals.rs

#[enum_builder_variant(Animal)]
struct Dog {}

#[enum_builder_variant(Animal)]
struct Cow {}

#[enum_builder_variant(Animal)]
struct Fish {}

Tips

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.

Example

#[enum_builder]
#[enum_dispatch]
enum Animal {}

About

Simple macros that allow building enum types from variants that can be defined in multiple dispersed files in the crate.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages