diff --git a/src/bsd.rs b/src/bsd.rs index 4fffa93..43c9d1b 100644 --- a/src/bsd.rs +++ b/src/bsd.rs @@ -42,7 +42,7 @@ use crate::{ }; #[cfg(apple)] -const ALIGN: usize = size_of::(); +const ALIGN: usize = std::mem::size_of::(); #[cfg(bsd)] // See https://github.com/freebsd/freebsd-src/blob/524a425d30fce3d5e47614db796046830b1f6a83/sys/net/route.h#L362-L371 @@ -68,9 +68,9 @@ asserted_const_with_type!(AF_LINK, AddressFamily, libc::AF_LINK, i32); asserted_const_with_type!(RTM_VERSION, u8, bindings::RTM_VERSION, u32); asserted_const_with_type!(RTM_GET, u8, bindings::RTM_GET, u32); -const_assert!(size_of::() + ALIGN <= u8::MAX as usize); -const_assert!(size_of::() + ALIGN <= u8::MAX as usize); -const_assert!(size_of::() <= u8::MAX as usize); +const_assert!(std::mem::size_of::() + ALIGN <= u8::MAX as usize); +const_assert!(std::mem::size_of::() + ALIGN <= u8::MAX as usize); +const_assert!(std::mem::size_of::() <= u8::MAX as usize); struct IfAddrs(*mut ifaddrs); @@ -183,8 +183,8 @@ union SockaddrStorage { fn sockaddr_len(af: AddressFamily) -> Result { let sa_len = match af { - AF_INET => size_of::(), - AF_INET6 => size_of::(), + AF_INET => std::mem::size_of::(), + AF_INET6 => std::mem::size_of::(), _ => { return Err(Error::new( ErrorKind::InvalidInput, @@ -203,7 +203,7 @@ impl From for SockaddrStorage { #[cfg(not(target_os = "solaris"))] #[allow(clippy::cast_possible_truncation)] // `sockaddr_in` len is <= u8::MAX per `const_assert!` above. - sin_len: size_of::() as u8, + sin_len: std::mem::size_of::() as u8, sin_family: AF_INET, sin_addr: in_addr { s_addr: u32::from_ne_bytes(ip.octets()), @@ -217,7 +217,7 @@ impl From for SockaddrStorage { #[cfg(not(target_os = "solaris"))] #[allow(clippy::cast_possible_truncation)] // `sockaddr_in6` len is <= u8::MAX per `const_assert!` above. - sin6_len: size_of::() as u8, + sin6_len: std::mem::size_of::() as u8, sin6_family: AF_INET6, sin6_addr: in6_addr { s6_addr: ip.octets(), @@ -250,7 +250,7 @@ impl RouteMessage { rtm: rt_msghdr { #[allow(clippy::cast_possible_truncation)] // `rt_msghdr` len + `ALIGN` is <= u8::MAX per `const_assert!` above. - rtm_msglen: (size_of::() + sa_len) as u16, + rtm_msglen: (std::mem::size_of::() + sa_len) as u16, rtm_version: RTM_VERSION, rtm_type: RTM_GET, rtm_seq: seq, @@ -276,14 +276,14 @@ impl RouteMessage { impl From<&RouteMessage> for &[u8] { fn from(value: &RouteMessage) -> Self { - debug_assert!(value.len() >= size_of::()); + debug_assert!(value.len() >= std::mem::size_of::()); unsafe { slice::from_raw_parts(ptr::from_ref(value).cast(), value.len()) } } } impl From<&[u8]> for rt_msghdr { fn from(value: &[u8]) -> Self { - debug_assert!(value.len() >= size_of::()); + debug_assert!(value.len() >= std::mem::size_of::()); unsafe { ptr::read_unaligned(value.as_ptr().cast()) } } } @@ -304,15 +304,15 @@ fn if_index_mtu(remote: IpAddr) -> Result<(u16, Option)> { loop { let mut buf = vec![ 0u8; - size_of::() + + std::mem::size_of::() + // There will never be `RTAX_MAX` sockaddrs attached, but it's a safe upper bound. - (RTAX_MAX as usize * size_of::()) + (RTAX_MAX as usize * std::mem::size_of::()) ]; let len = fd.read(&mut buf[..])?; - if len < size_of::() { + if len < std::mem::size_of::() { return Err(default_err()); } - let (reply, mut sa) = buf.split_at(size_of::()); + let (reply, mut sa) = buf.split_at(std::mem::size_of::()); let reply: rt_msghdr = reply.into(); if !(reply.rtm_version == query_version && reply.rtm_pid == pid diff --git a/src/windows.rs b/src/windows.rs index 1c76f26..247d28e 100644 --- a/src/windows.rs +++ b/src/windows.rs @@ -49,7 +49,9 @@ impl Drop for MibTablePtr { fn drop(&mut self) { if !self.0.is_null() { // Free the memory allocated by GetIpInterfaceTable. - unsafe { FreeMibTable(self.0.cast()) }; + unsafe { + FreeMibTable(self.0.cast()); + } } } }