From 6e1589ff7df198752f1aa37b94efc64be80fcc61 Mon Sep 17 00:00:00 2001 From: mhart Date: Sun, 11 Oct 2020 20:10:17 +0200 Subject: [PATCH] Change Option<> in parse_orientation() parse_instruction() for Result --- src/main.rs | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/main.rs b/src/main.rs index 313f30a..c10155e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,22 +11,22 @@ enum Instruction { F, } -fn parse_orientation(c: char) -> Option { +fn parse_orientation(c: char) -> Result { match c { - 'N' => Some(Orientation::N), - 'E' => Some(Orientation::E), - 'S' => Some(Orientation::S), - 'W' => Some(Orientation::W), - _ => None, + 'N' => Ok(Orientation::N), + 'E' => Ok(Orientation::E), + 'S' => Ok(Orientation::S), + 'W' => Ok(Orientation::W), + _ => Err("Invalid character, does not match any orientations"), } } -fn parse_instruction(c: char) -> Option { +fn parse_instruction(c: char) -> Result { match c { - 'L' => Some(Instruction::L), - 'R' => Some(Instruction::R), - 'F' => Some(Instruction::F), - _ => None, + 'L' => Ok(Instruction::L), + 'R' => Ok(Instruction::R), + 'F' => Ok(Instruction::F), + _ => Err("Invalid character, does not match any instructions"), } }