Created
April 20, 2015 22:39
-
-
Save archer884/e0d6910f9c0f1baf1118 to your computer and use it in GitHub Desktop.
Struct enum variants
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
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