SHARE
TWEET

Untitled

a guest Jul 17th, 2019 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn main() {
  2.     let vec: Vec<Result<i32, i32>> = vec![Ok(1), Err(2), Ok(1), Err(2)];
  3.  
  4.     let result: Result<Vec<i32>, i32> = vec.iter().cloned().collect();
  5.     println!("collect res: {:?}", result);
  6.  
  7.     let (good, bad) = vec
  8.         .iter()
  9.         .cloned()
  10.         .fold((vec![], vec![]), |(mut oks, mut errs), res| {
  11.             match res {
  12.                 Ok(x) => oks.push(x),
  13.                 Err(e) => errs.push(e),
  14.             };
  15.             (oks, errs)
  16.         });
  17.  
  18.     println!("fold: good {:?}, bad: {:?}", good, bad);
  19. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top