#enums #macro #proc-macro #variant #collection #data #field

macro enum_macros

A collection of useful macros to make working with enums easier

3 releases

new 0.0.3 Oct 11, 2024
0.0.2 Oct 1, 2024
0.0.1 Jul 28, 2024

#383 in Procedural macros

Download history 106/week @ 2024-07-24 30/week @ 2024-07-31 8/week @ 2024-09-11 7/week @ 2024-09-18 98/week @ 2024-09-25 61/week @ 2024-10-02 133/week @ 2024-10-09

300 downloads per month

MIT/Apache

21KB
357 lines

enum-macros

Crates.io Version docs.rs (with version)

A collection of useful macros to make working with enums easier.

Current features

The current set of macros is not fixed yet. More macros will likely be added or removed in the future.

Each macro can be enabled and disabled individually by its respective Cargo feature if it is not wanted. By default, all are enabled.

  • custom_discriminant: allows using arbitrary values as discriminants and converting from and to them
  • marker_type: creates a copy of an enum where no field holds data
  • NextVariant: allows moving forward through the variants of an enum
  • VariantAmount: adds a constant storing the amount of variants the enum has
  • UnwrapVariant: adds methods for unwrapping variants of an enum

no_std compability

The crate is fully #![no_std] compatible at the moment. Future versions may introduce a subset of features that require std under a new std crate feature.

Dependencies

~240–680KB
~16K SLoC