core::ptr

Function fn_addr_eq

Source
pub fn fn_addr_eq<T: FnPtr, U: FnPtr>(f: T, g: U) -> bool
🔬This is a nightly-only experimental API. (ptr_fn_addr_eq #129322)
Expand description

Compares the addresses of the two function pointers for equality.

Function pointers comparisons can have surprising results since they are never guaranteed to be unique and could vary between different code generation units. Furthermore, different functions could have the same address after being merged together.

This is the same as f == g but using this function makes clear that you are aware of these potentially surprising semantics.

§Examples

#![feature(ptr_fn_addr_eq)]
use std::ptr;

fn a() { println!("a"); }
fn b() { println!("b"); }
assert!(!ptr::fn_addr_eq(a as fn(), b as fn()));