use color::Color;
use core::{ops, mem};
#[derive(Copy, Clone, Debug, Hash, PartialEq, Eq)]
#[repr(u8)]
pub enum Direction {
North,
East,
Northeast,
Southeast,
Northwest,
Southwest,
West,
South,
}
impl ops::Not for Direction {
type Output = Direction;
#[inline]
fn not(self) -> Direction {
unsafe { mem::transmute(7 - self as u8) }
}
}
impl Direction {
#[inline]
pub fn forward(color: Color) -> Direction {
match color {
Color::White => Direction::North,
Color::Black => Direction::South,
}
}
#[inline]
pub fn backward(color: Color) -> Direction {
Direction::forward(!color)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn not() {
use self::Direction::*;
static NOT: [(Direction, Direction); 4] = [
(North, South),
(East, West),
(Northeast, Southwest),
(Northwest, Southeast),
];
for &(a, b) in &NOT {
assert_eq!(a, !b);
assert_eq!(!a, b);
}
}
}