SHARE
TWEET

Untitled

a guest Aug 17th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn bad(vec1: Vec<u8>, vec2: Vec<u8>) -> Vec<(u8, Option<u8>)> {
  2.     let it1 = vec1.into_iter().rev();
  3.     let mut it2 = vec2.into_iter().rev();
  4.     it1.map(|v1| {
  5.         (v1, it2.next())
  6.     }).rev().collect()
  7. }
  8.  
  9. fn good(vec1: Vec<u8>, vec2: Vec<u8>) -> Vec<(u8, Option<u8>)> {
  10.     let it1 = vec1.into_iter().rev();
  11.     let mut it2 = vec2.into_iter().rev();
  12.     let vec3: Vec<_> = it1.map(|v1| {
  13.         (v1, it2.next())
  14.     }).collect();
  15.     vec3.into_iter().rev().collect()
  16. }
  17.  
  18. pub fn main() {
  19.     let count = vec![0, 1, 2, 3, 4, 5];
  20.     println!("Should be  : {:?}'),", good(count.clone(), vec![0, 1, 2, 3]));
  21.     println!("but instead: {:?}", bad(count.clone(), vec![0, 1, 2, 3]));
  22. }
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
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top