fn main() {
let mut val = 0;
println!("{:p}", val as *mut i32); // null pointer
println!("{:p}", &mut val as *mut i32); // the address of the variable
}
You need to cast the reference to a *mut c_int before casting to *mut c_void. To retrieve the value from the *mut c_void, you need to cast it to a *const c_int first (*mut c_int works too), and then dereference it (which is an unsafe operation):
use libc::c_int;
use libc::c_void;
fn main() {
let mut val : c_int = 0;
let p_val = &mut val as *mut c_int as *mut c_void;
println!("ptr: {:p}", p_val);
println!("value: {:}", unsafe { *(p_val as *const c_int) });
}