Skip to content

Instantly share code, notes, and snippets.

@durka
Last active March 14, 2018 03:49
Show Gist options
  • Save durka/91670268e1abee137ddeed4bee7e6b19 to your computer and use it in GitHub Desktop.
Save durka/91670268e1abee137ddeed4bee7e6b19 to your computer and use it in GitHub Desktop.
// `parts` is an Iterator<Item=&str>
// `conv_mod` returns a `Result<Vec<String>, _>`
let themod = if parts.peek().is_some() {
if !parts.peek().unwrap().starts_with("Key") {
Some(conv_mod(parts.next().unwrap())?)
} else {
None
}
} else {
None
};
// thanks smitra
let themod = parts.peek().map(|p| {
if !p.starts_with("Key") {
Some(conv_mod(parts.next().unwrap())?)
} else {
None
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment