fn main() { let nums = vec![1, 2, 3, 4, 5]; let doubled: Vec<i32> = nums.iter().map(|n| n * 2).collect(); for d in &doubled { println!("{}", d); } }
Output
Click Run to execute, or Check to validate.
Ask questions or share tips about this tutorial
Sign in to join the discussion