If I have a type like MyEnum, how can I map it in cases where not every variant is parameterized?
For example, I\'d like to convert from
Some languages (like C++), use Duck Typing: if it quacks like a duck, it must be a duck, and therefore names matter. Rust does not.
In Rust, names are just some display utility for us mere humans, the B in MyEnum and MyEnum may happen to have the same visual representation, but they are completely different syntactic entities as far as the language is concerned.
There are multiple ways to alleviate your pain, though:
build.rs script can be used as wellI'll show-case the latter:
enum MyEnumImpl {
A,
B,
C,
}
enum MyEnum {
Independent(MyEnumImpl),
Dependent(T),
}
Obviously, the latter makes it much easier to manually map things.