Created
October 2, 2019 13:48
-
-
Save mykhailokrainik/981048c69e23da8a465ddfc31fcc7341 to your computer and use it in GitHub Desktop.
Convert Vec<Result<_>> to Result<Vec<_>>
This file contains hidden or 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
type CustomError = &'static str; | |
type Result<T> = std::result::Result<T, CustomError>; | |
fn main() -> Result<()> { | |
let val = vec![Ok(1), Ok(2),Err("Some error")]; | |
let res: Vec<i32> = val.into_iter().collect::<Result<_>>()?; // Error: "Some error" | |
println!("{:?}", res); | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment