I'm trying to compare a variable of enum type stored in a vector of structs, with a variable of the same type passed into my function as a parameter. So, both enums are stored in variables. However, I'm getting unexpected results. I'm using the matches!()
macro for comparison. Can anyone explain this behaviour?
enum Foo {
A,
B,
}
fn main() {
let a = Foo::A;
if matches!(a, Foo::A) { println!("expected") }
if matches!(a, Foo::B) { println!("not expected 1") }
if matches!(Foo::B, a) { println!("not expected 2") }
let b = Foo::B;
if matches!(a, b) { println!("not expected 3") }
}
Output:
expected
not expected 2
not expected 3