Crate enum_to_enum[][src]

Expand description

enum_to_enum

enum_to_enum exposes a derive macro to easily generate possibly effectful enum-to-enum conversions: #[derive(FromEnum)].

The destination enum must be annotated to specify one or more source enums we will generate From implementations for.

The generated From implementations rely on provided From or TryFrom implementations for each corresponding field or tuple-item in struct-like or tuple-like enums.

Each variant of the destination enum may specify one or more variants of the source enums that should correspond to the destination variant. If multiple variants of a given source enum might correspond to the same destination variant, the destination variant must have at least 1 field or tuple item and the corresponding TryFrom implementations will be invoked in the order in which they appear on the destination enum until one of them succeeds.

Effectful conversions require users to provide a struct implementing the WithEffects trait and a conversion will be generated from each source enum to the provided effect_container.

Traits

Any struct specified as an effect_container for the from_enum attribute must implement WithEffects. WithEffects specifies a container for a value, the result of some conversion, and an ordered list of effects arising from that conversion.

Derive Macros

You can add #[derive(FromEnum)] to any enum to generate a possibly effectful From implementation to convert from other source enums to the annotated destination enum.