Prototype of the parsing_config() func

This commit is contained in:
Martin HART 2020-10-28 12:36:56 +01:00
parent 555a0ff6b8
commit 430e706831
1 changed files with 11 additions and 0 deletions

View File

@ -18,6 +18,16 @@ use std::fs;
use std::io;
mod robot;
mod world;
/// Parse the config file, generate the world and robot pool.
fn parse_config(raw_conf: String, pool: &Vec<robot::Robot>) -> Result<world::World, &'static str> {
// test exemple, i am currently writting the real code.
// This function return the map OR an error inside a Result so we
// can catch error using '?' in main
// we also create robots here and put them into the pool.
Ok(world::World { x: 5, y: 5 })
}
/// Retrieve the content of a file and return it as a string.
fn open_file(filename: &str) -> io::Result<String> {
@ -42,6 +52,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let raw_conf = open_file(matches.value_of("file").unwrap_or("two_robots.txt"))?;
let robot_pool: Vec<robot::Robot> = Vec::new();
let world = parse_config(raw_conf, &robot_pool)?;
Ok(())
}