I\'m having a lot of fun trying to solve the robot simulator Exercism exercise, but I\'m facing a value moving problem for which I don\'t seem to be able to come up with an
Looking at the other users answers, you can actually do it with fold :
pub fn instructions(self, instructions: &str) -> Self {
instructions.chars().fold(self, |robot, c| {
match c {
'L' => robot.turn_left(),
'R' => robot.turn_right(),
'A' => robot.advance(),
_ => panic!("unexpected char")
}
})
}
It seems to keep moving back robot into the scope.