enum-tree-derive 0.1.0

Derive macros for the enum-tree crate
Documentation

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.