denumic
denumic
macro is to create enum-based runtime dispatched traits.
When applied to a trait
, it exports the definition of the trait that would be passed to other denumic
attributes on enum
s.
When applied to an enum
, it generates a macro that can be used to dispatch to the appropriate implementation of the trait for each variant of the enum
.
From
and TryFrom
are also automatically implemented for the enum
, as long as it does not break coherence rules, so that it can be converted to and from the variants.
Example
use denumic;
// Generic parameters of the trait and the enum could be finly merged matching by names.
// Note that the identifiers `used` before the trait definition also have to be `use`d before the enum definition.
// Associated types and consts can be specified using attributes:
// As for types that are not a valid `expr`, quote them instead of raw types:
;