Created
January 21, 2018 09:42
-
-
Save illicitonion/9f49f7de0eff262e1e54b5d6d21712ac to your computer and use it in GitHub Desktop.
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
pub fn try_collect<Item, Error, Iter: std::iter::Iterator<Item=Result<Item, Error>>, Collection: Default + Extend<Item>>(iter: Iter) -> Result<Collection, Error> { | |
let mut values: Collection = Default::default(); | |
for item in iter { | |
match item { | |
Ok(v) => values.extend(std::iter::once(v)), | |
Err(err) => return Err(err), | |
} | |
} | |
return Ok(values) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment