#[derive(Debug, Eq, PartialEq)] pub enum Action { North, East, South, West, Left, Right, Forward, } impl From for Action { fn from(input: char) -> Self { match input { 'N' => Self::North, 'E' => Self::East, 'S' => Self::South, 'W' => Self::West, 'L' => Self::Left, 'R' => Self::Right, 'F' => Self::Forward, _ => unreachable!("{input}"), } } } #[derive(Debug)] pub struct Instruction { pub action: Action, pub value: i32, } impl From<&str> for Instruction { fn from(input: &str) -> Self { let mut chars = input.chars(); let action = chars.next().map(Into::into).unwrap(); let value = chars.collect::().parse().unwrap(); Self { action, value } } }