From 0931835850fbc85357a27b9a6cd05b9a0abbf09e Mon Sep 17 00:00:00 2001 From: Volodymyr Patuta <6977238-fiplox@users.noreply.gitlab.com> Date: Wed, 28 Oct 2020 18:20:37 +0100 Subject: [PATCH] added hash in execute_instruction --- src/robot.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/robot.rs b/src/robot.rs index 59fa0bd..09901c4 100644 --- a/src/robot.rs +++ b/src/robot.rs @@ -9,11 +9,15 @@ pub struct Robot { impl Robot { /// Create new `Robot` with given id, `Orientation`, `Position` and instructions. - fn new(id: i32, o: Orientation, p: Position, i: Vec) -> Robot { + fn new(id: u32, o: Orientation, p: Position, i: Vec) -> Robot { Robot { id, o, p, i } } /// Apply given instruction to a `Robot`. - fn execute_instruction(&mut self) -> Result<(), &'static str> { + fn execute_instruction( + &mut self, + hash: &mut std::collections::HashMap, + ) -> Result<(), &'static str> { + hash.remove(&self.p); // we need to insert the new position after calling execute_instruction() match self.i.pop() { Some(instruction) => match instruction { 'L' => Ok(match self.o { @@ -50,6 +54,7 @@ enum Orientation { } /// Struct to store robot position. +#[derive(PartialEq, Eq, Hash)] struct Position { x: i32, y: i32,