Created
June 1, 2014 17:33
-
-
Save emk/4fa148663826e5b06f63 to your computer and use it in GitHub Desktop.
Rust: Using 'collect' after we map something which might fail
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
impl FromStr for LanguageTag { | |
fn from_str(s: &str) -> Option<LanguageTag> { | |
fn parse(s: &str) -> Option<Tag> { from_str(s) } | |
let parsed: Option<Vec<Tag>> = collect(s.split('-').map(parse)); | |
match parsed { | |
Some(components) => Some(LanguageTag { components: components }), | |
None => None | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment