What are drop scopes for captured variable in closure?
⚓ Rust 📅 2025-05-29 👤 surdeus 👁️ 10Given a function, or closure, there are drop scopes for:
- The entire function
- Each statement
- Each expression
- Each block, including the function body
- In the case of a block expression, the scope for the block and the expression are the same scope.
fn main(){
let i = String::from("i");
let f = move ||{
println!("{i}");
};
}
It is unclear what the drop scope of the captured variable i is.
5 posts - 2 participants
🏷️ rust_feed