indexed_valued_enums-0.8.0 has been yanked.
A crate to easily create C-like enums resolving into values
Example of valued enum use
This creates an public enum where every Number has an associated value of type NumberDescription
use create_indexed_valued_enum;
use Indexed;
use Valued;
create_indexed_valued_enum!
Example of creating a valued enum
To implement it write: create_indexed_valued_enum!{ Visibility enum EnumsName, derives: [Derive1, Derive2, ...], features: [Feature1, Feature2, ...], value type: TypeOfValue, Variant1, Value1, Variant2, Value2, ... VariantN, ValueN }
use create_indexed_valued_enum;
create_indexed_valued_enum!
On each of the fields you can indicate different parameters to change the implementation of the enum:
- Visibility: Visibility of the enum
- EnumsName: Name the enum will have
- Derives: List of derive macros you want the enum to execute
- TypeOfValue: type of the values the variant's resolve to
- Pairs of Variant, Value: Name of the variant's to create along to the name they resolve to, the values must be const and have 'static lifetime
- Features: List of specific implementations you want your enum to use, they are the following ones:
- DerefToValue: The enum implements Deref, making variants to resolve to their value directly, remember however these values won't mutate as they are constant references (&'static TypeOfValue), this is also the reason why these values require their life-time to be 'static
- Clone: The enum implements clone calling [Indexed::from_discriminant], this way it's not required for the Derive Clone macro to expand to large enums
- Delegators: Implements delegator functions over this enum that call on the methods from [Indexed] and [Valued], this way it is not required to import or use the indexed_valued_enums crate directly, however, it doesn't delegate the methods [Valued::value_to_variant] and [Valued::value_to_variant_opt] as they require the type of value to implement [PartialEq], however, you can delegate these too with the feature ValueToVariantDelegators
- ValueToVariantDelegators: Implements delegator functions for [Valued::value_to_variant] and [Valued::value_to_variant_opt]
- Serialize: Implements serde's Serialize trait where it serializes to an usize that represents this enum's discriminant
- Deserialize: Implements serde's Deserialize trait where it deserializes an enum variant's from it's enum's discriminant
- NanoSerBin: Implements nanoserde's SerBin trait where it serializes to an usize that represents this enum's discriminant
- NanoDeBin: Implements nanoserde's DeBin trait where it deserializes an enum variant's from it's enum's discriminant
- NanoSerJson: Implements nanoserde's SerJson trait where it serializes to an usize that represents this enum's discriminant
- NanoDeJson: Implements nanoserde's DeJson trait where it deserializes an enum variant's from it's enum's discriminant