use match instead of if/else

Rotation is an enum so leverage the compiler to tell us
we've considered all cases
This commit is contained in:
Daniel Barlow 2023-11-01 00:23:58 +00:00
parent c812b79363
commit f09e4d4bee

View File

@ -39,14 +39,17 @@ mod rover {
}
pub fn rotate((lon, lat, direction) : &Rover, rotation: Rotation) -> Rover {
if rotation == Rotation::Left {
let new_d = next_direction(*direction);
(*lon, *lat, new_d)
} else {
let new_d = next_direction(*direction);
let new_d = next_direction(new_d);
let new_d = next_direction(new_d);
(*lon, *lat, new_d)
match rotation {
Rotation::Left => {
let new_d = next_direction(*direction);
(*lon, *lat, new_d)
},
Rotation::Right => {
let new_d = next_direction(*direction);
let new_d = next_direction(new_d);
let new_d = next_direction(new_d);
(*lon, *lat, new_d)
}
}
}
}