#derive #macro #enums #md-match

macro md_match_derive

This crate provides the derive macro for md-match

1 unstable release

0.1.0 Feb 17, 2023

#873 in #enums

26 downloads per month
Used in md_match

MIT license

5KB
65 lines

md-match

A macro to support md-match.

use md_match::derive::MdMatch;
use md_match::{md_match, MdMatch};

#[derive(MdMatch)]
enum A {
    A1(String),
}

#[derive(MdMatch)]
enum B {
    B1(String),
}

#[test]
fn it_works() {
    let (mut a, mut b) = (A::A1(String::from("hello")), B::B1(String::from("world")));

    let (va_ref, vb_ref) = md_match!(&a, &b => |x, y| (x, y));
    assert_eq!(va_ref, "hello");
    assert_eq!(vb_ref, "world");

    md_match!(&mut a, &mut b => |x, y| {
        *x = String::from("world");
        *y = String::from("hello");
    });

    let (va, vb) = md_match!(a, b => |x, y| (x, y));
    assert_eq!(va, "world");
    assert_eq!(vb, "hello");
}

lib.rs:

MdMatch

This crate provides the derive macro for md-match. Please refer to https://github.com/Mu001999/md-match for how to set this up.

Dependencies

~1.5MB
~34K SLoC