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:
parent
c812b79363
commit
f09e4d4bee
19
src/main.rs
19
src/main.rs
@ -39,14 +39,17 @@ mod rover {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn rotate((lon, lat, direction) : &Rover, rotation: Rotation) -> Rover {
|
pub fn rotate((lon, lat, direction) : &Rover, rotation: Rotation) -> Rover {
|
||||||
if rotation == Rotation::Left {
|
match rotation {
|
||||||
let new_d = next_direction(*direction);
|
Rotation::Left => {
|
||||||
(*lon, *lat, new_d)
|
let new_d = next_direction(*direction);
|
||||||
} else {
|
(*lon, *lat, new_d)
|
||||||
let new_d = next_direction(*direction);
|
},
|
||||||
let new_d = next_direction(new_d);
|
Rotation::Right => {
|
||||||
let new_d = next_direction(new_d);
|
let new_d = next_direction(*direction);
|
||||||
(*lon, *lat, new_d)
|
let new_d = next_direction(new_d);
|
||||||
|
let new_d = next_direction(new_d);
|
||||||
|
(*lon, *lat, new_d)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user