This is really bad....
This commit is contained in:
parent
194d6f5df2
commit
44545cdc07
17
src/main.rs
17
src/main.rs
@ -25,20 +25,27 @@ fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::Wor
|
|||||||
let mut lines = conf.lines();
|
let mut lines = conf.lines();
|
||||||
// The first line of the config file should be the World.
|
// The first line of the config file should be the World.
|
||||||
let raw_line: &str = match lines.next() {
|
let raw_line: &str = match lines.next() {
|
||||||
None => return Err("Could not read the first line of the config file !"),
|
|
||||||
Some(raw) => raw,
|
Some(raw) => raw,
|
||||||
|
None => return Err("Could not read the first line of the config file !"),
|
||||||
};
|
};
|
||||||
let mut tokens = raw_line.split_whitespace();
|
let mut tokens = raw_line.split_whitespace();
|
||||||
let token1 = match tokens.next() {
|
let token1 = match tokens.next() {
|
||||||
None => return Err("Could not read the first token of the first line !"),
|
|
||||||
Some(raw) => raw,
|
Some(raw) => raw,
|
||||||
|
None => return Err("Could not read the first token of the first line !"),
|
||||||
};
|
};
|
||||||
let token2 = match tokens.next() {
|
let token2 = match tokens.next() {
|
||||||
None => return Err("Could not read the second token of the first line !"),
|
|
||||||
Some(raw) => raw,
|
Some(raw) => raw,
|
||||||
|
None => return Err("Could not read the second token of the first line !"),
|
||||||
};
|
};
|
||||||
println!("{}, {}", token1, token2);
|
let x: i32 = match token1.parse::<i32>() {
|
||||||
Ok(world::World { x: 5, y: 5 })
|
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.
|
/// Retrieve the content of a file and return it as a string.
|
||||||
|
Loading…
Reference in New Issue
Block a user