From 44545cdc07c8bf47c3ed3be7ea321631ae1f8fc3 Mon Sep 17 00:00:00 2001 From: Martin HART Date: Wed, 28 Oct 2020 18:05:22 +0100 Subject: [PATCH] This is really bad.... --- src/main.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main.rs b/src/main.rs index cb3ab9d..4668dc7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -25,20 +25,27 @@ fn parse_config(conf: String, pool: &mut Vec) -> Result 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::() { + Ok(x) => x, + Err(err) => return Err("Could not convert token one from the first string to i32"), + }; + let y: i32 = match token2.parse::() { + 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.