Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug when variant value has `as <type>` #1

Open
faern opened this Issue Nov 3, 2018 · 0 comments

Comments

Projects
None yet
1 participant
@faern
Copy link

faern commented Nov 3, 2018

Really handy crate 👌

But I have found that if used on an enum like this:

#[derive(TryFromPrimitive)]
#[repr(u8)]
pub enum Bar {
    A = 10,
    B = 20 as u8,
}

it produces the following code:

impl Bar {
    pub fn try_from(n: u8) -> Option<Bar> {
        match n {
            10u8 => Some(Bar::A),
            10u8 => Some(Bar::B),
            _ => None,
        }
    }
}

Which is clearly wrong, because now Bar::try_from(20) will return None instead of Some(Bar::B).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.