2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2017-06-24 13:26:04 -05:00
|
|
|
macro_rules! enum_number {
|
|
|
|
($name:ident { $($variant:ident = $value:expr, )* }) => {
|
|
|
|
enum $name {
|
|
|
|
$($variant = $value,)*
|
|
|
|
}
|
|
|
|
|
|
|
|
fn foo(value: i32) -> Option<$name> {
|
|
|
|
match value {
|
|
|
|
$( $value => Some($name::$variant), )*
|
|
|
|
_ => None
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum_number!(Change {
|
|
|
|
Down = -1,
|
|
|
|
None = 0,
|
|
|
|
Up = 1,
|
|
|
|
});
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
if let Some(Change::Down) = foo(-1) {} else { panic!() }
|
|
|
|
}
|