Skip to content

Instantly share code, notes, and snippets.

@archer884
Created April 20, 2015 22:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save archer884/e0d6910f9c0f1baf1118 to your computer and use it in GitHub Desktop.
Save archer884/e0d6910f9c0f1baf1118 to your computer and use it in GitHub Desktop.
Struct enum variants
enum TestEnum {
DataA { f: String, l: String },
DataB { n: String },
}
impl std::fmt::Display for TestEnum {
fn fmt(&self, fmt: &mut std::fmt::Formatter) -> Result<(), std::fmt::Error> {
match self {
&TestEnum::DataA { ref f, ref l } => write!(fmt, "{}, {}", l, f),
&TestEnum::DataB { ref n } => fmt.write_str(&n),
}
}
}
fn main() {
let x = TestEnum::DataA {
f: "Maximus".to_string(),
l: "Hardcorion".to_string(),
};
let y = TestEnum::DataB {
n: "Maximus Hardcorion".to_string(),
};
println!("{}", x);
println!("{}", y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment