1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2025-03-19 14:17:51 +02:00

Add main method to code snippet (#2630)

The code snippet wouldn't compile/run directly because of a missing
`main` method.

Also remove unnecessary `&`.
This commit is contained in:
Nicole L 2025-02-07 01:08:10 -08:00 committed by GitHub
parent af6dff53c2
commit c05f0b6f02
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -9,12 +9,14 @@ In addition to the `next` method that defines how an iterator behaves, the
customized iterators. customized iterators.
```rust,editable ```rust,editable
let result: i32 = (1..=10) // Create a range from 1 to 10 fn main() {
.filter(|&x| x % 2 == 0) // Keep only even numbers let result: i32 = (1..=10) // Create a range from 1 to 10
.map(|x| x * x) // Square each number .filter(|x| x % 2 == 0) // Keep only even numbers
.sum(); // Sum up all the squared 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);
}
``` ```
<details> <details>