Answers for "armanriazi•rust•error•E0277•can't compare `&{"

0

armanriazi•rust•error•E0277•can't compare `&{

//resolve  let v_copied: Vec<_> = a.iter().copied().collect();
//copied(): This is useful when you have an iterator over &T, but you need an iterator over T.



fn main(){
let a = [1, 2, 3];

let v_copied: Vec<_> = a.iter().collect();

// copied is the same as .map(|&x| x)
let v_map: Vec<_> = a.iter().map(|&x| x).collect();

assert_eq!(v_copied, vec![1, 2, 3]); //Error
assert_eq!(v_map, vec![1, 2, 3]);

}
Posted by: Guest on May-05-2022

Code answers related to "armanriazi•rust•error•E0277•can't compare `&{"

Browse Popular Code Answers by Language