about summary refs log tree commit diff
path: root/src/libstd/sys_common
diff options
context:
space:
mode:
Diffstat (limited to 'src/libstd/sys_common')
-rw-r--r--src/libstd/sys_common/unixsocket.rs28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/libstd/sys_common/unixsocket.rs b/src/libstd/sys_common/unixsocket.rs
index 286e0e9f37f..c7d71ae6790 100644
--- a/src/libstd/sys_common/unixsocket.rs
+++ b/src/libstd/sys_common/unixsocket.rs
@@ -113,6 +113,34 @@ impl<'a> io::Write for &'a UnixStream {
 }
 
 impl SocketAddr {
+    /// Returns true if and only if the address is unnamed.
+    ///
+    /// # Examples
+    ///
+    /// A named address:
+    ///
+    /// ```no_run
+    /// use std::os::unix::net::UnixListener;
+    ///
+    /// let socket = UnixListener::bind("/tmp/sock").unwrap();
+    /// let addr = socket.local_addr().expect("Couldn't get local address");
+    /// assert_eq!(addr.is_unnamed(), false);
+    /// ```
+    ///
+    /// An unnamed address:
+    ///
+    /// ```
+    /// use std::os::unix::net::UnixDatagram;
+    ///
+    /// let socket = UnixDatagram::unbound().unwrap();
+    /// let addr = socket.local_addr().expect("Couldn't get local address");
+    /// assert_eq!(addr.is_unnamed(), true);
+    /// ```
+    #[stable(feature = "unix_socket", since = "1.10.0")]
+    pub fn is_unnamed(&self) -> bool {
+        self.0.is_unnamed()
+    }
+
     /// Returns the contents of this address if it is a `pathname` address.
     ///
     /// # Examples