1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
#[derive(Clone, Debug, PartialEq)] pub enum Direction { Left, Right, Up, Down, } impl Direction { pub fn x(&self) -> isize { match *self { Direction::Left => 1, Direction::Right => -1, _ => 0, } } pub fn y(&self) -> isize { match *self { Direction::Up => 1, Direction::Down => -1, _ => 0, } } pub fn opposite(&self) -> Self { match *self { Direction::Left => Direction::Right, Direction::Right => Direction::Left, Direction::Up => Direction::Down, Direction::Down => Direction::Up, } } } #[cfg(test)] mod test;