100-exercises-to-learn-rust icon indicating copy to clipboard operation
100-exercises-to-learn-rust copied to clipboard

Simplify solution to 06_ticket_management/01_arrays

Open iurii-kyrylenko opened this issue 2 months ago • 0 comments

https://github.com/mainmatter/100-exercises-to-learn-rust/blob/d347d1f72ee77b96b2d51f0405292fd0590e8162/exercises/06_ticket_management/01_arrays/src/lib.rs#L7-L15

All variants in the enum are unit-only. According to enum casting, its discriminant can be directly accessed with a numeric cast.

So, instead of https://github.com/mainmatter/100-exercises-to-learn-rust/blob/d347d1f72ee77b96b2d51f0405292fd0590e8162/exercises/06_ticket_management/01_arrays/src/lib.rs#L24-L33 a simplified version can be used:

pub fn get_temperature(&self, day: Weekday) -> Option<i32> {
    self.temperatures[day as usize]
}

pub fn set_temperature(&mut self, day: Weekday, temperature: i32) {
    self.temperatures[day as usize] = Some(temperature);
}

iurii-kyrylenko avatar Oct 08 '25 09:10 iurii-kyrylenko