deduplicate code in rotate method

main
Daniel Barlow 2023-11-03 19:00:27 +00:00
parent 9a9bad4f71
commit 95d201eb2f
1 changed files with 9 additions and 8 deletions

View File

@ -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)
}
}
}