matched_enums 1.3.0

A macro that provides the option to bin enum attribute to match-statements. This makes it easier to convert values into enums.
Documentation
//! This is a slightly more complex example using struct unpacking and guards
//! to convert an arbitrary input direction into an enumartion.

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() {
    // Pure values

    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);

    // Mixed values

    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);
}