1
Fork 0
advent-of-code/source/year_2020/day_12/extra.rs

43 lines
763 B
Rust
Raw Normal View History

2022-10-03 16:02:40 +00:00
#[derive(Debug, Eq, PartialEq)]
pub enum Action {
North,
East,
South,
West,
Left,
Right,
Forward,
}
impl From<char> 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::<String>().parse().unwrap();
Self { action, value }
}
}