Last active
August 29, 2015 14:03
-
-
Save kenpratt/d5400c885c32126affc6 to your computer and use it in GitHub Desktop.
Trying to match String content inside an Enum.
This file contains 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
// 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