For example in Elixir's case statement, the following code is valid and will match 10 to 1:
x = 1
case 10 do
^x -> "Won't match"
_ -> "Will match"
end
In Rust however, ^ is not a valid operator for this use case. It just gives an error that says something like "expected pattern, found ^". I have tried doing this:
let x = 1;
match 10 {
x => "Won't match",
_ => "Will match",
}
But it binds 10 to x and returns "Won't match" (it is equivalent to "x @ _"). Is there a way to dynamically include x so that whatever x is, it will match against its value? (Note: I realize I can just use an if statement but I'm curious if the match statement provides a solution)