remove trash check and use unwrap that will NEVER EVER panic!
This commit is contained in:
parent
48c78dab70
commit
95851f229b
51
src/main.rs
51
src/main.rs
@ -81,10 +81,7 @@ fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::Wor
|
|||||||
};
|
};
|
||||||
let mut w: Vec<i32> = Vec::with_capacity(2);
|
let mut w: Vec<i32> = Vec::with_capacity(2);
|
||||||
for n in raw_world.split_whitespace() {
|
for n in raw_world.split_whitespace() {
|
||||||
let v: i32 = match n.parse::<i32>() {
|
let v: i32 = n.parse::<i32>().unwrap();
|
||||||
Ok(x) => x,
|
|
||||||
Err(_) => return Err(String::from("World config is broken.")),
|
|
||||||
};
|
|
||||||
w.push(v);
|
w.push(v);
|
||||||
}
|
}
|
||||||
let world = world::World { x: w[0], y: w[1] };
|
let world = world::World { x: w[0], y: w[1] };
|
||||||
@ -109,47 +106,12 @@ fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::Wor
|
|||||||
};
|
};
|
||||||
|
|
||||||
let mut setup = raw_setup.split_whitespace();
|
let mut setup = raw_setup.split_whitespace();
|
||||||
let pos_x = match setup.next() {
|
let pos_x = setup.next().unwrap();
|
||||||
Some(raw) => raw,
|
let pos_y = setup.next().unwrap();
|
||||||
None => {
|
let orientation = setup.next().unwrap();
|
||||||
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 !",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
// Convert values of the setup line
|
// Convert values of the setup line
|
||||||
let r_x = match pos_x.parse::<i32>() {
|
let r_x = pos_x.parse::<i32>().unwrap();
|
||||||
Ok(raw) => raw,
|
let r_y = pos_y.parse::<i32>().unwrap();
|
||||||
Err(_) => {
|
|
||||||
return Err(String::from(
|
|
||||||
"Could not convert the first token of the setup ligne to i32 !",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let r_y = match pos_y.parse::<i32>() {
|
|
||||||
Ok(raw) => raw,
|
|
||||||
Err(_) => {
|
|
||||||
return Err(String::from(
|
|
||||||
"Could not convert the second token of the setup ligne to i32 !",
|
|
||||||
))
|
|
||||||
}
|
|
||||||
};
|
|
||||||
let r_o = match orientation {
|
let r_o = match orientation {
|
||||||
"N" => robot::Orientation::N,
|
"N" => robot::Orientation::N,
|
||||||
"E" => robot::Orientation::E,
|
"E" => robot::Orientation::E,
|
||||||
@ -168,7 +130,6 @@ fn parse_config(conf: String, pool: &mut Vec<robot::Robot>) -> Result<world::Wor
|
|||||||
}
|
}
|
||||||
|
|
||||||
let r = robot::Robot::new(r_id, r_o, robot::Position { x: r_x, y: r_y }, inst);
|
let r = robot::Robot::new(r_id, r_o, robot::Position { x: r_x, y: r_y }, inst);
|
||||||
|
|
||||||
// Load robot inside the pool.
|
// Load robot inside the pool.
|
||||||
match check_map(&r, &world) {
|
match check_map(&r, &world) {
|
||||||
Ok(()) => pool.push(r),
|
Ok(()) => pool.push(r),
|
||||||
|
Loading…
Reference in New Issue
Block a user