Given two same length Vec<u8>, trying to select an element from each index with a given probability p: f32, as follows,
fn select(xs: &Vec<u8>, ys: &Vec<u8>, p: f32) -> Vec<u8> {
let mut rng = rand::thread_rng();
xs
.iter()
.zip(ys.iter())
.map(|(a, b)| if rng.gen_range(0.0..1.0) < p { a } else { b })
.collect()
}
However,
value of type `Vec<u8>` cannot be built from `std::iter::Iterator<Item=&u8>`
How to collect an iterator into a new vector?