From bbcbfd4d419e454638d5699a2b89873e9ef74d35 Mon Sep 17 00:00:00 2001 From: Martin HART Date: Wed, 28 Oct 2020 13:09:07 +0100 Subject: [PATCH] Catch the first ligne of the config file or throw a error ! --- src/main.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 344b600..851406c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -22,10 +22,12 @@ mod world; /// Parse the config file, generate the world and robot pool. fn parse_config(raw_conf: String, pool: &Vec) -> Result { - // 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. + let mut lines = raw_conf.lines(); + // The first line of the config file should be the World. + let raw_map: &str = match lines.next() { + None => return Err("Could not read the first line of the config file !"), + Some(raw) => raw, + }; Ok(world::World { x: 5, y: 5 }) }