Convert values of the setup line

This commit is contained in:
Martin HART 2020-10-30 12:08:12 +01:00
parent 5c9aeabd03
commit f4a1eac5b7
1 changed files with 17 additions and 0 deletions

View File

@ -93,6 +93,7 @@ fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::Wor
if raw_inst.is_empty() {
return Err("This line should not be empty !");
}
// Parse the setup line of the robot.
let mut setup = raw_setup.split_whitespace();
let pos_x = match setup.next() {
None => return Err("Could not read the first token of the setup line !"),
@ -106,6 +107,22 @@ fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::Wor
None => return Err("Could not read the third token of the setup line !"),
Some(raw) => raw,
};
// Convert values of the setup line
let r_x = match pos_x.parse::<i32>() {
Err(_) => return Err("Could not convert the first token of the setup ligne to i32 !"),
Ok(raw) => raw,
};
let r_y = match pos_y.parse::<i32>() {
Err(_) => return Err("Could not convert the second token of the setup ligne to i32 !"),
Ok(raw) => raw,
};
let r_o = match orientation {
"N" => robot::Orientation::N,
"E" => robot::Orientation::E,
"S" => robot::Orientation::S,
"W" => robot::Orientation::W,
_ => return Err("The third token of the setup line do not match any orientations !"),
};
println!("{}", raw_setup);
println!("{}", raw_inst);
}