Skip to content

Instantly share code, notes, and snippets.

@mykhailokrainik
Created October 2, 2019 13:48
Show Gist options
  • Save mykhailokrainik/981048c69e23da8a465ddfc31fcc7341 to your computer and use it in GitHub Desktop.
Save mykhailokrainik/981048c69e23da8a465ddfc31fcc7341 to your computer and use it in GitHub Desktop.
Convert Vec<Result<_>> to Result<Vec<_>>
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