A function pointer identifies the start of a function’s executable code, rather than a data value. In Rust, a function’s signature describes its arguments and return value; for example, `fn() -> ()` takes no arguments and returns unit. The address can be passed to another component so it can call the function later. section 12.7.1 section 12.10
Listing 12.10 Casting a function to usize
fn noop() {}
fn main() {
let fn_ptr = noop as usize;
let typed_fn_ptr = noop as *const fn() -> ();
println!("noop as usize: 0x{:x}", fn_ptr);
println!("noop as *const T: {:p}", typed_fn_ptr); #1
}
The `noop` example casts one function address to `usize` and to `*const fn() -> ()`. Both printed values identify the same location. The address will differ on your machine. section 12.7.1
Registering a signal handler
`libc::signal` associates a signal with a handler function. The handler has type `fn(i32) -> ()`, but this interface accepts an untyped pointer, so the example casts the handler to `usize`. When the signal arrives, the registered function runs; the handler keeps its work minimal by setting a shutdown flag for the main loop to check. section 12.6.2 section 12.12
A closure that captures variables is different: it has a compiler-generated type that contains values from its environment. A closure that captures nothing can also serve as a function pointer. Keep that distinction in mind when choosing a callback. section 10.3



