diff --git a/library/std/src/os/unix/net/addr.rs b/library/std/src/os/unix/net/addr.rs index b8e8e9b506d3..7f64533cb67d 100644 --- a/library/std/src/os/unix/net/addr.rs +++ b/library/std/src/os/unix/net/addr.rs @@ -131,7 +131,8 @@ impl SocketAddr { /// /// # Errors /// - /// Returns an error if the path is longer than `SUN_LEN`. + /// Returns an error if the path is longer than `SUN_LEN` or if it contains + /// NULL bytes. /// /// # Examples /// @@ -141,13 +142,22 @@ impl SocketAddr { /// use std::path::Path; /// /// # fn main() -> std::io::Result<()> { - /// let address = SocketAddr::unix("/path/to/socket")?; + /// let address = SocketAddr::from_path("/path/to/socket")?; /// assert_eq!(address.as_pathname(), Some(Path::new("/path/to/socket"))); /// # Ok(()) /// # } /// ``` + /// + /// Creating a `SocketAddr` with a NULL byte results in an error. + /// + /// ``` + /// #![feature(unix_socket_creation)] + /// use std::os::unix::net::SocketAddr; + /// + /// assert!(SocketAddr::from_path("/path/with/\0/bytes").is_err()); + /// ``` #[unstable(feature = "unix_socket_creation", issue = "65275")] - pub fn unix
(path: P) -> io::Result (path: P) -> io::Result