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.