md_match 0.1.1

A macro to support md-match syntax.
Documentation
  • Coverage
  • 100%
    6 out of 6 items documented1 out of 3 items with examples
  • Size
  • Source code size: 4.92 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 190.61 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Links
  • mu001999/md-match
    0 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • mu001999

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