enum-tree 0.1.0

Derives for hierarchical enums: const variant enumeration, From conversions, and ancestor wrapping
Documentation
  • Coverage
  • 80%
    4 out of 5 items documented1 out of 2 items with examples
  • Size
  • Source code size: 19.84 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 295.82 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 10s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • DannyStoll1

enum-tree

Derive macros for working with enum variants:

  • DeepVariants -- generates a compile-time array containing every reachable variant value, recursively descending into singleton tuple variants whose inner type also derives DeepVariants.
  • EnumFrom -- generates From impls for the enum from fields tagged #[enum_from], with optional conversion via via = ... and per-field defaults via default = ....
  • IntoAncestors -- generates From impls that build an ancestor enum from a descendant by chaining through intermediate enums.
use enum_tree::DeepVariants;

#[derive(DeepVariants, PartialEq, Eq, Debug)]
enum Inner {
    A,
    B,
}

#[derive(DeepVariants, PartialEq, Eq, Debug)]
enum Outer {
    Unit,
    Nested(Inner),
}

assert_eq!(
    Outer::DEEP_VARIANTS,
    &[Outer::Unit, Outer::Nested(Inner::A), Outer::Nested(Inner::B)],
);

Renaming the crate

Pass #[enum_tree(crate = path)] when the runtime crate has been re-exported under a different name.