Pattern matching as a boolean expression

Hello,
I am currently searching for a better way of doing this:

let vec: Vec<TestEnum> = ...;
vec.iter().any(|x| if let TestEnum::Test1 = x {
        true
    } else {
        false
    });

This seems strange to me that rust hasn't included a better way of doing this. Like:

let vec: Vec<TestEnum> = ...;
vec.iter().any(|x| if let TestEnum::Test1 = x);

If you know how to do something like this or another better way.

Thank's for reading me,
ccgauche.

Have a look at the matches! macro. Docs here.

Thanks this is what I was searching for!

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.