mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 23:34:48 +00:00
26 lines
497 B
Rust
26 lines
497 B
Rust
// run-pass
|
|
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!() }
|
|
}
|