// 實作 impl impl Action for Day { // return &str type fnactl(&self) -> &str { // match self matchself { // by using | or operator &Day::Saturday | &Day::Sunday => "I sleep all day!", // "_" equal the other _ => "I must work hard." } } }
fnmain() { let today = Day::Monday; let other_day = Day::Sunday; println!("Today is {:?}, {}", today, today.actl()); println!("Tomorrow is {:?}, {}.", other_day, other_day.actl()); }
// output: Today is Monday, I must work hard. // output: Tomorrow is Sunday, I sleep all day.