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
use rstest::rstest;

use crate::{Matched, UnmatchedError};

#[derive(Matched, PartialEq, Debug)]
#[matched_enum(use_partial=true, value_type=i32)]
enum Signature {
    #[matches(1..)]
    Positive,

    #[matches(..=-1)]
    Negative,
}

#[rstest]
#[case(0, Err(UnmatchedError{}))]
#[case(1, Ok(Signature::Positive))]
#[case(i32::MAX, Ok(Signature::Positive))]
#[case(-1, Ok(Signature::Negative))]
#[case(i32::MIN, Ok(Signature::Negative))]
fn get_signature_from_value(
    #[case] input: i32,
    #[case] expected: Result<Signature, UnmatchedError>,
) {
    assert_eq!(Signature::try_from(input), expected);
}

// > **NOTE**: There was a bug where if `use_partial` is used after `value_type`,
// it would skip `use_partial`.

#[derive(Matched, PartialEq, Debug)]
#[matched_enum(use_partial=true, value_type=i32)]
enum Signature2 {
    #[matches(1..)]
    Positive,

    #[matches(..=-1)]
    Negative,
}

#[rstest]
#[case(0, Err(UnmatchedError{}))]
#[case(1, Ok(Signature2::Positive))]
#[case(i32::MAX, Ok(Signature2::Positive))]
#[case(-1, Ok(Signature2::Negative))]
#[case(i32::MIN, Ok(Signature2::Negative))]
fn get_signature_from_value_with_use_partial_as_final_attribute(
    #[case] input: i32,
    #[case] expected: Result<Signature2, UnmatchedError>,
) {
    assert_eq!(Signature2::try_from(input), expected);
}