Skip to content

Instantly share code, notes, and snippets.

@emk
Created June 1, 2014 17:33
Show Gist options
  • Save emk/4fa148663826e5b06f63 to your computer and use it in GitHub Desktop.
Save emk/4fa148663826e5b06f63 to your computer and use it in GitHub Desktop.
Rust: Using 'collect' after we map something which might fail
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