Easier "local" code inside closures

⚓ Rust    📅 2025-08-16    👤 surdeus    👁️ 4      

surdeus

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

Read full topic

🏷️ Rust_feed