When looking at unix-socket
, I came across this code:
let timeout = unsafe {
let mut timeout: libc::timeval = mem::zeroed();
let mut size = mem::size_of::<libc::timeval>() as libc::socklen_t;
try!(cvt(libc::getsockopt(self.0,
libc::SOL_SOCKET,
kind,
&mut timeout as *mut _ as *mut _,
&mut size as *mut _ as *mut _)));
timeout
};
I was curious about these lines in particular:
&mut timeout as *mut _ as *mut _,
&mut size as *mut _ as *mut _
Why is it necessary to perform two casts to a mutable raw pointer in a row? Why wouldn't it have been sufficient to only cast once?