[rust-dev] Query Related to enum

Sanghyeon Seo sh4.seo at samsung.com
Tue Mar 5 03:09:10 PST 2013


> enum A {
>     a = 0,
>     b = 1,
>     c = 2
> }
>
> What I want is when I pass 2, I get c from it.
> Is there some built-in for this or some other way.

This is issue #2132 and there is no completely satisfactory answer yet.
https://github.com/mozilla/rust/issues/2132

You can use unsafe code (case::transmute), or you can do pattern matching:

match number {
    0 => a,
    1 => b,
    2 => c,
    _ => fail!()
}


More information about the Rust-dev mailing list