about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLinus Färnstrand <faern@faern.net>2022-07-17 09:48:56 +0200
committerLinus Färnstrand <faern@faern.net>2022-07-17 09:48:56 +0200
commitb20b69a79b4e8bfc3574c767ec798d356d33045d (patch)
tree9ad137a9a8488687d219ae992315bb615c6c72a7
parent7aabd85faa9e78e40161839b14946c5aa6750086 (diff)
downloadrust-b20b69a79b4e8bfc3574c767ec798d356d33045d.tar.gz
rust-b20b69a79b4e8bfc3574c767ec798d356d33045d.zip
Move SocketAddrCRepr to sys_common
-rw-r--r--library/std/src/net/addr.rs31
-rw-r--r--library/std/src/sys_common/net.rs35
2 files changed, 35 insertions, 31 deletions
diff --git a/library/std/src/net/addr.rs b/library/std/src/net/addr.rs
index 13d85f23035..53fee952a7a 100644
--- a/library/std/src/net/addr.rs
+++ b/library/std/src/net/addr.rs
@@ -596,37 +596,6 @@ impl<I: Into<IpAddr>> From<(I, u16)> for SocketAddr {
     }
 }
 
-/// A type with the same memory layout as `c::sockaddr`. Used in converting Rust level
-/// SocketAddr* types into their system representation. The benefit of this specific
-/// type over using `c::sockaddr_storage` is that this type is exactly as large as it
-/// needs to be and not a lot larger. And it can be initialized more cleanly from Rust.
-#[repr(C)]
-pub(crate) union SocketAddrCRepr {
-    v4: c::sockaddr_in,
-    v6: c::sockaddr_in6,
-}
-
-impl SocketAddrCRepr {
-    pub fn as_ptr(&self) -> *const c::sockaddr {
-        self as *const _ as *const c::sockaddr
-    }
-}
-
-impl<'a> IntoInner<(SocketAddrCRepr, c::socklen_t)> for &'a SocketAddr {
-    fn into_inner(self) -> (SocketAddrCRepr, c::socklen_t) {
-        match *self {
-            SocketAddr::V4(ref a) => {
-                let sockaddr = SocketAddrCRepr { v4: a.into_inner() };
-                (sockaddr, mem::size_of::<c::sockaddr_in>() as c::socklen_t)
-            }
-            SocketAddr::V6(ref a) => {
-                let sockaddr = SocketAddrCRepr { v6: a.into_inner() };
-                (sockaddr, mem::size_of::<c::sockaddr_in6>() as c::socklen_t)
-            }
-        }
-    }
-}
-
 #[stable(feature = "rust1", since = "1.0.0")]
 impl fmt::Display for SocketAddr {
     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
diff --git a/library/std/src/sys_common/net.rs b/library/std/src/sys_common/net.rs
index e49337999d2..47c6a82f646 100644
--- a/library/std/src/sys_common/net.rs
+++ b/library/std/src/sys_common/net.rs
@@ -700,3 +700,38 @@ impl fmt::Debug for UdpSocket {
         res.field(name, &self.inner.as_raw()).finish()
     }
 }
+
+////////////////////////////////////////////////////////////////////////////////
+// Converting SocketAddr to libc representation
+////////////////////////////////////////////////////////////////////////////////
+
+/// A type with the same memory layout as `c::sockaddr`. Used in converting Rust level
+/// SocketAddr* types into their system representation. The benefit of this specific
+/// type over using `c::sockaddr_storage` is that this type is exactly as large as it
+/// needs to be and not a lot larger. And it can be initialized more cleanly from Rust.
+#[repr(C)]
+pub(crate) union SocketAddrCRepr {
+    v4: c::sockaddr_in,
+    v6: c::sockaddr_in6,
+}
+
+impl SocketAddrCRepr {
+    pub fn as_ptr(&self) -> *const c::sockaddr {
+        self as *const _ as *const c::sockaddr
+    }
+}
+
+impl<'a> IntoInner<(SocketAddrCRepr, c::socklen_t)> for &'a SocketAddr {
+    fn into_inner(self) -> (SocketAddrCRepr, c::socklen_t) {
+        match *self {
+            SocketAddr::V4(ref a) => {
+                let sockaddr = SocketAddrCRepr { v4: a.into_inner() };
+                (sockaddr, mem::size_of::<c::sockaddr_in>() as c::socklen_t)
+            }
+            SocketAddr::V6(ref a) => {
+                let sockaddr = SocketAddrCRepr { v6: a.into_inner() };
+                (sockaddr, mem::size_of::<c::sockaddr_in6>() as c::socklen_t)
+            }
+        }
+    }
+}