This is really bad....

This commit is contained in:
Martin HART 2020-10-28 18:05:22 +01:00
parent 194d6f5df2
commit 44545cdc07

View File

@ -25,20 +25,27 @@ fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::Wor
let mut lines = conf.lines();
// The first line of the config file should be the World.
let raw_line: &str = match lines.next() {
None => return Err("Could not read the first line of the config file !"),
Some(raw) => raw,
None => return Err("Could not read the first line of the config file !"),
};
let mut tokens = raw_line.split_whitespace();
let token1 = match tokens.next() {
None => return Err("Could not read the first token of the first line !"),
Some(raw) => raw,
None => return Err("Could not read the first token of the first line !"),
};
let token2 = match tokens.next() {
None => return Err("Could not read the second token of the first line !"),
Some(raw) => raw,
None => return Err("Could not read the second token of the first line !"),
};
println!("{}, {}", token1, token2);
Ok(world::World { x: 5, y: 5 })
let x: i32 = match token1.parse::<i32>() {
Ok(x) => x,
Err(err) => return Err("Could not convert token one from the first string to i32"),
};
let y: i32 = match token2.parse::<i32>() {
Ok(x) => x,
Err(err) => return Err("Could not convert token two from the first string to i32"),
};
Ok(world::World { x: x, y: y })
}
/// Retrieve the content of a file and return it as a string.