Skip to content

Instantly share code, notes, and snippets.

@kenpratt
Last active August 29, 2015 14:03
Show Gist options
  • Save kenpratt/d5400c885c32126affc6 to your computer and use it in GitHub Desktop.
Save kenpratt/d5400c885c32126affc6 to your computer and use it in GitHub Desktop.
Trying to match String content inside an Enum.
// works, but ugly
fn check1(s: Option<String>) {
match s {
Some(t) => {
match t.as_slice() {
"test" => println!("yep"),
_ => println!("nope")
}
},
None => println!("nope")
}
}
// fails to compile
fn check2(s: Option<String>) {
match s {
Some("test") => println!("yep"),
_ => println!("nope")
}
}
fn main() {
check2(Some("test".to_str()));
check2(Some("test2".to_str()));
check2(None);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment