mars-rover-fe

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 95d201eb2f97c1dc6a93f3ec03900a1be67a92d5
parent 9a9bad4f7133f5f82e85068088dd34d19e3e36d0
Author: Daniel Barlow <dan@telent.net>
Date:   Fri,  3 Nov 2023 19:00:27 +0000

deduplicate code in rotate method

Diffstat:
Msrc/main.rs | 17+++++++++--------
1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/main.rs b/src/main.rs @@ -44,18 +44,19 @@ mod rover { pub fn rotate(&self, rotation: Rotation) -> Rover { let Rover(lon, lat, direction) = self; - match rotation { + let new_direction = match rotation { Rotation::Left => { - let new_d = next_direction(*direction); - Rover(*lon, *lat, new_d) + next_direction(*direction) }, Rotation::Right => { - let new_d = next_direction(*direction); - let new_d = next_direction(new_d); - let new_d = next_direction(new_d); - Rover(*lon, *lat, new_d) + next_direction( + next_direction( + next_direction(*direction) + ) + ) } - } + }; + Rover(*lon, *lat, new_direction) } } }