I am not sure how they are useful, but at least they seems interesting. And please let me know if I misunderstood something or did not used words accurately and precisely.
Thanks very much! Now enumx/enumx_derive has been rewritten using similar mechanisms to get rid of #[enumx] macro magic.
In version 0.2.0, both ad-hoc enums or user-defined enums can be exchanged from one to another.
use enumx::Exchange;
#[derive(Exchange,Debug,PartialEq,Eq)]
enum One<T0> {
The(T0),
}
#[derive(Exchange,Debug,PartialEq,Eq)]
enum Two<T0,T1> {
Former(T0),
Latter(T1),
}
#[derive(Exchange,Debug,PartialEq,Eq)]
enum Three<T0,T1,T2> {
First(T0),
Second(T1),
Third(T2),
}
let one = One::<i32>::from_variant( 2018 );
let one = One::<i32>::exchange_from( one );
assert_eq!( one, One::The( 2018 ));
let two = Two::<String,i32>::exchange_from( one );
assert_eq!( two, Two::Latter( 2018 ));
let two = Two::<i32,String>::exchange_from( two );
assert_eq!( two, Two::Former( 2018 ));
let three = Three::<bool,String,i32>::exchange_from( two );
assert_eq!( three, Three::Third( 2018 ));
let three = Three::<i32,String,bool>::exchange_from( three );
assert_eq!( three, Three::First( 2018 ));
And version 0.3 is probably on its way, to make #[derive(Exchange)] a first-class structural enum type, and get rid of ExchangeFrom/ExchangeInto, and name suffixes “_ex”/“_named” in CeX APIs.
I will dig deeper into this topic, and make the forth version of the RFC, then send a pr. Perhaps in one month. Any advice and suggestions will be appreciated.