Skip to content

Instantly share code, notes, and snippets.

@jacobmischka
Created April 9, 2017 20:41
Show Gist options
  • Save jacobmischka/7f3ba41ad4dec0c052d3088c773f5998 to your computer and use it in GitHub Desktop.
Save jacobmischka/7f3ba41ad4dec0c052d3088c773f5998 to your computer and use it in GitHub Desktop.
PatientSex
pub trait CodeValue {
fn value(&self) -> &str;
fn from(value: &str) -> Self;
}
pub enum PatientSex {
Male,
Female,
Missing,
Unknown
}
impl CodeValue for PatientSex {
fn value(&self) -> &str {
use self::PatientSex::*;
match *self {
Male => "Male",
Female => "Female",
Missing => "Missing",
Unknown => "Unknown"
}
}
fn from(sex: &str) -> PatientSex {
use self::PatientSex::*;
match sex {
"M" | "Male" => Male,
"F" | "Female" => Female,
"" => Missing,
_ => Unknown
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment