Created
April 9, 2017 23:05
-
-
Save jacobmischka/aa25850aa1dc37d5bd60b1a2d6a6f079 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
macro_rules! code_value_enum { | |
( | |
$NAME:ident { | |
$( | |
$VARIANT:ident => $OUT:expr; { | |
<= $( $IN:pat )|+ | |
} | |
),* | |
} | |
) => ( | |
#[derive(Clone, Copy, Debug)] | |
pub enum $NAME { | |
$( | |
$VARIANT, | |
)* | |
} | |
impl CodeValue for $NAME { | |
fn value(&self) -> &str { | |
match *self { | |
$( | |
$NAME::$VARIANT => $OUT, | |
)* | |
} | |
} | |
fn from_value(value: &str) -> $NAME { | |
match value { | |
$( | |
$( | |
$IN | |
)|+ => $NAME::$VARIANT, | |
)* | |
} | |
} | |
} | |
); | |
} | |
code_value_enum! { | |
PatientSex { | |
Male => "Male"; { | |
<= "M" | "Male" | |
}, | |
Female => "Female"; { | |
<= "F" | "Female" | |
}, | |
Missing => "Missing"; { | |
<= "" | |
}, | |
Unknown => "Unknown"; { | |
<= _ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment