using a closure, example:
// Alternate vectors' items
let x = vec![1, 3, 5, 7, 9];
let y = vec![2, 4, 6, 8, 10];
let z: Vec<i32> = Err(()).unwrap_or_else(|()| {
// Result
let mut new_vec: Vec<i32> = vec![];
// Note: range may vary depending on both vectors' size, this is an example
for i in 0..5 {
new_vec.push(x[i]);
new_vec.push(y[i]);
}
new_vec
});
println!("x: {:?}\ny: {:?}\nz: {:?}", x, y, z);
Genius or noob?
you could also type let z = { .. }; since rust is expression-based
I really feel like it was you trolling TBH.
Обсуждают сегодня