Guest User

Untitled

a guest
Jun 22nd, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. extern crate rayon;
  2.  
  3.  
  4. use std::error::Error;
  5. use rayon::iter::{IntoParallelRefIterator, ParallelIterator};
  6.  
  7. fn long_computation(x: u32) -> Result<u32, Box<Error>> {
  8. match x {
  9. 4 => Err(Error::),
  10. _ => Ok(42)
  11. }
  12. }
  13.  
  14. fn main() {
  15.  
  16. let xs = vec![1, 2, 3, 4, 5, 6];
  17.  
  18. let results : Vec<Result<u32, Box<Error>>> = xs
  19. .par_iter()
  20. .map(|&x| Ok(long_computation(x)? + 1))
  21. .collect();
  22.  
  23. }
Add Comment
Please, Sign In to add comment