Change Option<> in

parse_orientation()
parse_instruction()
for Result<Instruction, &'static str>
This commit is contained in:
mhart 2020-10-11 20:10:17 +02:00
parent c2d6e3422d
commit 6e1589ff7d

View File

@ -11,22 +11,22 @@ enum Instruction {
F,
}
fn parse_orientation(c: char) -> Option<Orientation> {
fn parse_orientation(c: char) -> Result<Orientation, &'static str> {
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<Instruction> {
fn parse_instruction(c: char) -> Result<Instruction, &'static str> {
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"),
}
}