2023-11-01 21:36:58 +00:00
|
|
|
// functions6.rs
|
|
|
|
//
|
|
|
|
// Here you can practice special functions called `closures`, that can capture
|
|
|
|
// variables of their parent context.
|
|
|
|
// Fix the code below to make it compile, without changing the two closure
|
|
|
|
// definitions.
|
|
|
|
//
|
|
|
|
// Execute `rustlings hint functions6` or use the `hint` watch subcommand for
|
|
|
|
// some hints.
|
|
|
|
|
|
|
|
fn main() {
|
2024-09-29 19:34:29 +01:00
|
|
|
// TODO: ensure the definition of captured variable
|
2023-11-01 21:36:58 +00:00
|
|
|
let closure_1 = |input_var: u32| -> u32 {input_var + outer_var};
|
|
|
|
println!("Closure#1 returns {}", closure_1(5));
|
|
|
|
|
|
|
|
let closure_2 = |input_var| println!("Closure#2 (input_var {})", input_var);
|
|
|
|
closure_2(2);
|
2024-09-29 19:34:29 +01:00
|
|
|
closure_2("5"); // TODO: look at the captured variable type here
|
2023-11-01 21:36:58 +00:00
|
|
|
}
|