use super::intcode;\r
use std::collections::HashSet;\r
+use std::convert::TryFrom;\r
\r
#[derive(PartialEq, Eq, Copy, Clone, Debug)]\r
enum Direction { Up, Left, Down, Right }\r
\r
-impl Direction {\r
- fn from_char(c: char) -> Option<Self> {\r
+impl TryFrom<char> for Direction {\r
+ type Error = ();\r
+\r
+ fn try_from(c: char) -> Result<Self, ()> {\r
match c {\r
- '^' => Some(Direction::Up),\r
- '<' => Some(Direction::Left),\r
- 'v' => Some(Direction::Down),\r
- '>' => Some(Direction::Right),\r
- _ => None\r
+ '^' => Ok(Direction::Up),\r
+ '<' => Ok(Direction::Left),\r
+ 'v' => Ok(Direction::Down),\r
+ '>' => Ok(Direction::Right),\r
+ _ => Err(())\r
}\r
}\r
}\r
current_x = 0;\r
} else {\r
let c = (*c as u8) as char;\r
- if let Some(dir) = Direction::from_char(c) {\r
+ if let Ok(dir) = Direction::try_from(c) {\r
self.start_position = (current_x, self.board.len() as i32);\r
self.start_dir = dir\r
}\r