mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-11 13:19:18 +00:00
Closures as a separate exercises appeared to be missing, so I added some. Have placed them in the watch order after functions, which seemed reasonable.
24 lines
451 B
Rust
24 lines
451 B
Rust
// closure2.rs
|
|
// What is the difference between a closure and a function? Can you get this code
|
|
// to compile?
|
|
|
|
// Execute `rustlings hint closures2` for hints!
|
|
|
|
// I AM NOT DONE
|
|
|
|
fn output(closure) {
|
|
println!("What am I?");
|
|
closure();
|
|
}
|
|
|
|
fn main() {
|
|
|
|
fn actual() {
|
|
println!("I'm actually a function")
|
|
}
|
|
|
|
let actual_fn = actual;
|
|
let closure = || println!("I'm a closure");
|
|
output(closure);
|
|
output(actual_fn);
|
|
} |