How to compare enum without pattern matching

Use matches!, e.g.:

matches!(my_struct.my_enum, Unknown)

Alternatively, you can use PartialEq trait, for example, by #[derive]:

#[derive(PartialEq)]
enum MyEnum { ... }

Then your “ideal” variant will work as is. However, this requires that MyEnum‘s contents also implement PartialEq, which is not always possible/wanted.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)