Exerpad
🔥 0
0 XP
Exercise 2 · Chapter: Closures & IteratorsRequired+50 XP

Closure Capture

Create a variable multiplier set to 3. Then create a closure multiply that captures multiplier and multiplies its parameter by it. Print the result for 5 and 10.

Expected output:

5 x 3 = 15
10 x 3 = 30

Hints:

  • The closure captures multiplier from the outer scope
  • let multiply = |x: i32| x * multiplier;
rust
fn main() {
}
Output
Run your code to see the output here.