use matched_enums::Matched;
#[derive(Debug)]
struct Vector2 {
x: i64,
y: i64,
}
#[derive(Debug, Matched, PartialEq)]
#[matched_enum(value_type=Vector2)]
enum Direction {
#[matches(Vector2 {y: y @ 1.., ref x} if y.abs() > x.abs())]
Up,
#[matches(Vector2 {y: y @ ..=-1, ref x} if y.abs() > x.abs())]
Down,
#[matches(Vector2 {x: x @ 1.., ref y} if x.abs() > y.abs())]
Right,
#[matches(Vector2 {x: x @ ..=-1, ref y} if x.abs() > y.abs())]
Left,
#[matches(_)]
Neutal,
}
fn main() {
const UP: Vector2 = Vector2 { x: 0, y: 10 };
const DOWN: Vector2 = Vector2 { x: 0, y: -10 };
const RIGHT: Vector2 = Vector2 { x: 10, y: 0 };
const LEFT: Vector2 = Vector2 { x: -10, y: 0 };
assert_eq!(Direction::from(UP), Direction::Up);
assert_eq!(Direction::from(DOWN), Direction::Down);
assert_eq!(Direction::from(LEFT), Direction::Left);
assert_eq!(Direction::from(RIGHT), Direction::Right);
const UP_RIGHT: Vector2 = Vector2 { x: 42, y: 451 };
const UP_LEFT: Vector2 = Vector2 { x: 42, y: 451 };
assert_eq!(Direction::from(UP_RIGHT), Direction::Up);
assert_eq!(Direction::from(UP_LEFT), Direction::Up);
}