Annoucing EnumX and CeX: anonymous enum and checked exception in Rust

Project link

This is a proof of concept project aiming at implementing anonymous enum and "checked exception" like error-handling in Rust via proc-macro.

See EnumX doc and CeX doc for more.

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.


You might want to take a look at frunk::coproduct - Rust to see if such mechanisms can be used to lift any of the restrictions and caveats.

1 Like

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;

enum One<T0> {

enum Two<T0,T1> {

enum Three<T0,T1,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 ));

Version 0.2.1 has been published. Two documents for reference:

Structural enum types in Rust

Checked exception simulation in Rust

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.

1 Like

Thanks again for your hints. Without your help, lacking support of generics may be the deal-breaker of EnumX for a long time.

I am planning to make an RFC(enum_exchange: minimal support for ad-hoc enums). Would you please do me a favor to review on it?

Sadly I don't have a lot of time to review it right now. :frowning:

Roger that. :grin:

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.

I am pleased to announce that a preview of v0.3.0 is available, as an alpha version.


  • throws syntax support

  • First-class user-defined exchangeable enums, which make the API much more clean and easier to use.

  • Better documents.( still needs improvements :grin: )

1 Like

EnumX 0.3.0 and CeX 0.3.0 have been published.

EnumX highlights:

  • EnumxFrom and IntoEnumx as the uniform enum exchange trait. No need for distinguishing between FromVariant and ExchangeFrom, any more.

CeX highlights:

  • MapError as the only error conversion trait. No need for distinguishing between "throw" and "rethrow".

  • Generalized logging.

  • Be able to work with failure.

  • Throws syntax has been removed completely. Now CeX does things in a Rusty way.