let say_hello = || println!("hello");
How can I display the address of the closure?
>Solution :
You can use a raw pointer conversion:
fn main() {
let say_hello = || println!("hello");
let address = (&say_hello as *const _) as usize;
println!("{address}");
}
Also using std::ptr::addr_of and casting again:
let same_address = std::ptr::addr_of!(say_hello) as usize;