From c05f0b6f023bf39b8d7f96bfa63e449d010eeb51 Mon Sep 17 00:00:00 2001 From: Nicole L Date: Fri, 7 Feb 2025 01:08:10 -0800 Subject: [PATCH] Add `main` method to code snippet (#2630) The code snippet wouldn't compile/run directly because of a missing `main` method. Also remove unnecessary `&`. --- src/iterators/helpers.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/iterators/helpers.md b/src/iterators/helpers.md index 5ea5f4c2..8534fe51 100644 --- a/src/iterators/helpers.md +++ b/src/iterators/helpers.md @@ -9,12 +9,14 @@ In addition to the `next` method that defines how an iterator behaves, the customized iterators. ```rust,editable -let result: i32 = (1..=10) // Create a range from 1 to 10 - .filter(|&x| x % 2 == 0) // Keep only even numbers - .map(|x| x * x) // Square each number - .sum(); // Sum up all the squared numbers +fn main() { + let result: i32 = (1..=10) // Create a range from 1 to 10 + .filter(|x| x % 2 == 0) // Keep only even numbers + .map(|x| x * x) // Square each number + .sum(); // Sum up all the squared numbers -println!("The sum of squares of even numbers from 1 to 10 is: {}", result); + println!("The sum of squares of even numbers from 1 to 10 is: {}", result); +} ```