A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-165.rs
1fnmain(){
2lets=String::from("hi");
3letf=||println!("{}",s);
4f();
5println!("{}",s);
6}
Closures
Answer & explanation
Console output
hi
hi
Why
Because the closure only reads `s`, Rust captures it by shared reference, not by value. The original binding `s` keeps ownership, so after calling `f()` the variable is still valid and `println!` can use it a second time. Both lines print "hi".