diff --git a/src/main.rs b/src/main.rs index 9d4bc34..4d64130 100644 --- a/src/main.rs +++ b/src/main.rs @@ -78,14 +78,11 @@ fn parse_config(conf: String, pool: &mut Vec) -> Result = conf.split('\n').collect(); let raw_world = match ConfParser::parse(Rule::world, lines.remove(0)) { Ok(s) => s.as_str(), - Err(e) => return Err(format!("{}", e)), + Err(_) => return Err(String::from("World config is broken.")), }; let mut w: Vec = Vec::with_capacity(2); for n in raw_world.split_whitespace() { - let v: i32 = match n.parse::() { - Ok(x) => x, - Err(_) => return Err(String::from("World config is broken.")), - }; + let v: i32 = n.parse::().unwrap(); w.push(v); } let world = world::World { x: w[0], y: w[1] }; @@ -98,7 +95,7 @@ fn parse_config(conf: String, pool: &mut Vec) -> Result s.as_str(), - Err(e) => return Err(format!("{}", e)), + Err(_) => return Err(String::from("Robot setup is broken.")), }; let rand_instructions = gen_random_instructions(); @@ -110,47 +107,12 @@ fn parse_config(conf: String, pool: &mut Vec) -> Result raw, - None => { - return Err(String::from( - "Could not read the first token of the setup line !", - )) - } - }; - let pos_y = match setup.next() { - Some(raw) => raw, - None => { - return Err(String::from( - "Could not read the second token of the setup line !", - )) - } - }; - let orientation = match setup.next() { - Some(raw) => raw, - None => { - return Err(String::from( - "Could not read the third token of the setup line !", - )) - } - }; + let pos_x = setup.next().unwrap(); + let pos_y = setup.next().unwrap(); + let orientation = setup.next().unwrap(); // Convert values of the setup line - let r_x = match pos_x.parse::() { - Ok(raw) => raw, - Err(_) => { - return Err(String::from( - "Could not convert the first token of the setup ligne to i32 !", - )) - } - }; - let r_y = match pos_y.parse::() { - Ok(raw) => raw, - Err(_) => { - return Err(String::from( - "Could not convert the second token of the setup ligne to i32 !", - )) - } - }; + let r_x = pos_x.parse::().unwrap(); + let r_y = pos_y.parse::().unwrap(); let r_o = match orientation { "N" => robot::Orientation::N, "E" => robot::Orientation::E, @@ -169,7 +131,6 @@ fn parse_config(conf: String, pool: &mut Vec) -> Result pool.push(r),