Expand description
§Fast enum conversion
This crate provides zerocost conversion between enums. An enum Src can be converted to another enum Dest when the following satisfies:
- For each variants of
Src, counterparts exist inDest.
Here, an variant ans its “counterpart” satisfies all of them:
- Both has the same tag names
Fieldsof both variants are equal. For example, one has structural fields, another should have the same.- All corresponding type of
Fieldsare the same.
It performs zerocost conversion when following satisfies for all counterparts:
- The
std::mem::Discriminantof them are equal. - The fields has same offsets.
- Have consistent memory layouts.
Traits§
- Convert
To - It defines conversion between enums.
Attribute Macros§
- convert_
to - This macro implements
ConvertTotrait for the enum, with given types as its targets. Both source and destination should be annotated.