So, what exactly is "*const ()" in Rust? It seems I can "as" some primitive value (integer value, function) to this type in Rust like the code shown below:
let foo = 1;
let pointer = foo as *const (); // this works.
But for floating-point numbers and so on, the compiler doesn't allow us to do the above coercion, so what is "*const ()" in Rust? Is it similar to void*
in C/C++? If so, why doesn't it support pointing to floating-point numbers?
BTW, adding the case where this pattern is currently used in the Reference: https://doc.rust-lang.org/std/mem/fn.transmute.html.
fn foo() -> i32 {
0
}
let pointer = foo as *const (); // here it is!!!
let function = unsafe {
std::mem::transmute::<*const (), fn() -> i32>(pointer)
};
assert_eq!(function(), 0);