#[derive(Debug, PartialEq, Copy, Clone)] enum ShirtColor { Red, Blue, } struct Inventory { shirts: Vec, } impl Inventory { fn giveaway(&self, user_preference: Option) -> ShirtColor { user_preference.unwrap_or_else(|| self.most_stocked()) } fn most_stocked(&self) -> ShirtColor { let mut red_num = 0; let mut blue_num = 0; for color in &self.shirts { match color { ShirtColor::Red => red_num += 1, ShirtColor::Blue => blue_num += 1, } } if red_num > blue_num { ShirtColor::Red } else { ShirtColor::Blue } } } fn main() { let store = Inventory { shirts: vec![ShirtColor::Blue, ShirtColor::Red, ShirtColor::Blue], }; let user_pref1 = Some(ShirtColor::Red); let giveaway1 = store.giveaway(user_pref1); println!("The user with preference {:?} get {:?}",user_pref1,giveaway1); let user_pref2 = None; let giveaway2 = store.giveaway(user_pref2); println!("The user with preference {user_pref2:?} get {:?}", giveaway2); }