In Rust, matching a value like this works:
let x = 1;
match x {
1 => println!("one"),
2 => println!("two"),
_ => println!("something else")
}
But using values from a vector instead of hard-coded numbers in match
doesn't work:
let x = 1;
let list = vec![1, 2];
match x {
list[0] => println!("one"),
list[1] => println!("two"),
_ => println!("something else")
}
This fails with the message:
error: expected one of `=>`, `@`, `if`, or `|`, found `[`
--> src/main.rs:6:9
|
6 | list[0] => println!("one"),
| ^ expected one of `=>`, `@`, `if`, or `|` here
Why doesn't it work?