Add helper functions.

This commit is contained in:
hal8174 2024-02-21 23:14:07 +01:00
parent 5575cb134a
commit 6cbb389ee7

View file

@ -1,3 +1,4 @@
use core::panic;
use std::io::Write;
use base64::write;
@ -68,6 +69,25 @@ impl Direction {
Direction::Left => Direction::Down,
}
}
pub fn get_index(&self) -> u8 {
match self {
Direction::Up => 0,
Direction::Right => 1,
Direction::Down => 2,
Direction::Left => 3,
}
}
pub fn from_index(i: u8) -> Self {
match i {
0 => Direction::Up,
1 => Direction::Right,
2 => Direction::Down,
3 => Direction::Left,
_ => panic!(),
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]