- PartialEq
Enumeration and manual comparision
We can also compare variables holding enum variants, but for that to work we also need to derivede from the ParialEq trait. Basically we need to implement the operation that allows use to compare two values of this type.
examples/enums/weekdays-manual-comparision/src/main.rs
#[derive(PartialEq)] #[allow(dead_code)] enum Weekday { Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, Sunday, } // We need the allow dead_code beacause in this example // we did not use all the values that were listed in the enum fn main() { let today = Weekday::Saturday; let tomorrow = Weekday::Sunday; let market = Weekday::Sunday; if market == today { println!("Today is market day"); } if market == tomorrow { println!("Tomorrow is market day"); } }
Tomorrow is market day