closure can choose to only capture some namespace previously closure cannot just capture tom.title, it needs to capture the entire Emploee structure struct Emploee { name: String, title: String, } fn main() { let tom = Employee { name: "Tom".into(), title: "Engineer".into(), }; drop(tom.name); println!("title: {}", tom.title); let c = || println!("{}", tom.title); c(); }
What's new in Rust 2021
What's new in Rust 2021
What's new in Rust 2021
closure can choose to only capture some namespace previously closure cannot just capture tom.title, it needs to capture the entire Emploee structure struct Emploee { name: String, title: String, } fn main() { let tom = Employee { name: "Tom".into(), title: "Engineer".into(), }; drop(tom.name); println!("title: {}", tom.title); let c = || println!("{}", tom.title); c(); }