Add helper functions.
This commit is contained in:
parent
5575cb134a
commit
6cbb389ee7
1 changed files with 20 additions and 0 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
use core::panic;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
use base64::write;
|
use base64::write;
|
||||||
|
|
@ -68,6 +69,25 @@ impl Direction {
|
||||||
Direction::Left => Direction::Down,
|
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)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue