Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Enumeration and order

  • PartialEq
  • PartialOrd
#[derive(PartialOrd, 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 yesterday = Weekday::Friday;
    let today = Weekday::Saturday;
    let tomorrow = Weekday::Sunday;

    if yesterday < today {
        println!("Today is after yesterday");
    }
    if today < tomorrow {
        println!("Tomorrow is after today");
    }
}
Today is after yesterday
Tomorrow is after today