Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Easier "local" code inside closures
Hi!
Am I the only one that thinks this kind of code is a pain?:
let a = Rc::new("proc macro sucks");
let b = Rc::new(42);
// The bottom code is looooonng
let my_closure = {
let a = a.clone();
let b = b.clone();
move || { println!("{} {}", a, b) }
}
drop((a,b));
drop(my_closure);
Maybe this is a niche problem, maybe not, but it would be really nice to write something like:
let my_closure = move || { println!("{} {}", local { a.clone() }, local { b.clone() }) }
(not only for clone
of course)
Any thoughts?
3 posts - 2 participants
🏷️ Rust_feed