From 8f158bc62bbe05e99927f4e86c1c38182d187c1e Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Tue, 12 Nov 2019 22:07:39 +0100 Subject: [PATCH 1/5] Replace .unwrap() with ? in std::os::unix::net --- src/libstd/sys/unix/ext/mod.rs | 2 +- src/libstd/sys/unix/ext/net.rs | 384 ++++++++++++++++++++------------- 2 files changed, 237 insertions(+), 149 deletions(-) diff --git a/src/libstd/sys/unix/ext/mod.rs b/src/libstd/sys/unix/ext/mod.rs index ccbac1a3e4b59..8039dcd2208cb 100644 --- a/src/libstd/sys/unix/ext/mod.rs +++ b/src/libstd/sys/unix/ext/mod.rs @@ -16,7 +16,7 @@ //! use std::os::unix::prelude::*; //! //! fn main() { -//! let f = File::create("foo.txt").unwrap(); +//! let f = File::create("foo.txt")?; //! let fd = f.as_raw_fd(); //! //! // use fd with native unix bindings diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 42edd5dbbea7c..cfa157c66d102 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -142,9 +142,11 @@ impl SocketAddr { /// ```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); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixListener::bind("/tmp/sock")?; + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(addr.is_unnamed(), false); + /// } /// ``` /// /// An unnamed address: @@ -152,9 +154,11 @@ impl SocketAddr { /// ``` /// 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); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixDatagram::unbound()?; + /// 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 { @@ -175,9 +179,11 @@ impl SocketAddr { /// use std::os::unix::net::UnixListener; /// use std::path::Path; /// - /// let socket = UnixListener::bind("/tmp/sock").unwrap(); - /// let addr = socket.local_addr().expect("Couldn't get local address"); - /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock"))); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixListener::bind("/tmp/sock")?; + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock"))); + /// } /// ``` /// /// Without a pathname: @@ -185,9 +191,11 @@ impl SocketAddr { /// ``` /// 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.as_pathname(), None); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixDatagram::unbound()?; + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// assert_eq!(addr.as_pathname(), None); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn as_pathname(&self) -> Option<&Path> { @@ -247,11 +255,13 @@ impl<'a> fmt::Display for AsciiEscaped<'a> { /// use std::os::unix::net::UnixStream; /// use std::io::prelude::*; /// -/// let mut stream = UnixStream::connect("/path/to/my/socket").unwrap(); -/// stream.write_all(b"hello world").unwrap(); -/// let mut response = String::new(); -/// stream.read_to_string(&mut response).unwrap(); -/// println!("{}", response); +/// fn main() -> std::io::Result<()> { +/// let mut stream = UnixStream::connect("/path/to/my/socket")?; +/// stream.write_all(b"hello world")?; +/// let mut response = String::new(); +/// stream.read_to_string(&mut response)?; +/// println!("{}", response); +/// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub struct UnixStream(Socket); @@ -336,8 +346,10 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// let sock_copy = socket.try_clone().expect("Couldn't clone socket"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// let sock_copy = socket.try_clone().expect("Couldn't clone socket"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn try_clone(&self) -> io::Result { @@ -351,8 +363,10 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn local_addr(&self) -> io::Result { @@ -366,8 +380,10 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// let addr = socket.peer_addr().expect("Couldn't get peer address"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// let addr = socket.peer_addr().expect("Couldn't get peer address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn peer_addr(&self) -> io::Result { @@ -391,7 +407,7 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); + /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); /// ``` /// @@ -403,10 +419,12 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); - /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); + /// let err = result.unwrap_err(); + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { @@ -430,8 +448,11 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_write_timeout(Some(Duration::new(1, 0))) + /// .expect("Couldn't set write timeout"); + /// } /// ``` /// /// An [`Err`] is returned if the zero [`Duration`] is passed to this @@ -442,10 +463,12 @@ impl UnixStream { /// use std::net::UdpSocket; /// use std::time::Duration; /// - /// let socket = UdpSocket::bind("127.0.0.1:34254").unwrap(); - /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); - /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// fn main() -> std::io::Result<()> { + /// let socket = UdpSocket::bind("127.0.0.1:34254")?; + /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); + /// let err = result.unwrap_err(); + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_write_timeout(&self, timeout: Option) -> io::Result<()> { @@ -460,9 +483,11 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); - /// assert_eq!(socket.read_timeout().unwrap(), Some(Duration::new(1, 0))); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); + /// assert_eq!(socket.read_timeout()?, Some(Duration::new(1, 0))); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn read_timeout(&self) -> io::Result> { @@ -477,9 +502,12 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.set_write_timeout(Some(Duration::new(1, 0))).expect("Couldn't set write timeout"); - /// assert_eq!(socket.write_timeout().unwrap(), Some(Duration::new(1, 0))); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_write_timeout(Some(Duration::new(1, 0))) + /// .expect("Couldn't set write timeout"); + /// assert_eq!(socket.write_timeout()?, Some(Duration::new(1, 0))); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn write_timeout(&self) -> io::Result> { @@ -493,8 +521,10 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.set_nonblocking(true).expect("Couldn't set nonblocking"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_nonblocking(true).expect("Couldn't set nonblocking"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { @@ -508,9 +538,11 @@ impl UnixStream { /// ```no_run /// use std::os::unix::net::UnixStream; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// if let Ok(Some(err)) = socket.take_error() { - /// println!("Got error: {:?}", err); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// if let Ok(Some(err)) = socket.take_error() { + /// println!("Got error: {:?}", err); + /// } /// } /// ``` /// @@ -535,8 +567,10 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::net::Shutdown; /// - /// let socket = UnixStream::connect("/tmp/sock").unwrap(); - /// socket.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock"); + /// socket.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { @@ -697,18 +731,20 @@ impl IntoRawFd for net::UdpSocket { /// // ... /// } /// -/// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); +/// fn main() -> std::io::Result<()> { +/// let listener = UnixListener::bind("/path/to/the/socket")?; /// -/// // accept connections and process them, spawning a new thread for each one -/// for stream in listener.incoming() { -/// match stream { -/// Ok(stream) => { -/// /* connection succeeded */ -/// thread::spawn(|| handle_client(stream)); -/// } -/// Err(err) => { -/// /* connection failed */ -/// break; +/// // accept connections and process them, spawning a new thread for each one +/// for stream in listener.incoming() { +/// match stream { +/// Ok(stream) => { +/// /* connection succeeded */ +/// thread::spawn(|| handle_client(stream)); +/// } +/// Err(err) => { +/// /* connection failed */ +/// break; +/// } /// } /// } /// } @@ -773,11 +809,13 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; /// - /// match listener.accept() { - /// Ok((socket, addr)) => println!("Got a client: {:?}", addr), - /// Err(e) => println!("accept function failed: {:?}", e), + /// match listener.accept() { + /// Ok((socket, addr)) => println!("Got a client: {:?}", addr), + /// Err(e) => println!("accept function failed: {:?}", e), + /// } /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -800,9 +838,11 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; /// - /// let listener_copy = listener.try_clone().expect("try_clone failed"); + /// let listener_copy = listener.try_clone().expect("try_clone failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn try_clone(&self) -> io::Result { @@ -816,9 +856,11 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; /// - /// let addr = listener.local_addr().expect("Couldn't get local address"); + /// let addr = listener.local_addr().expect("Couldn't get local address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn local_addr(&self) -> io::Result { @@ -832,9 +874,11 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; /// - /// listener.set_nonblocking(true).expect("Couldn't set non blocking"); + /// listener.set_nonblocking(true).expect("Couldn't set non blocking"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { @@ -848,10 +892,12 @@ impl UnixListener { /// ```no_run /// use std::os::unix::net::UnixListener; /// - /// let listener = UnixListener::bind("/tmp/sock").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/tmp/sock")?; /// - /// if let Ok(Some(err)) = listener.take_error() { - /// println!("Got error: {:?}", err); + /// if let Ok(Some(err)) = listener.take_error() { + /// println!("Got error: {:?}", err); + /// } /// } /// ``` /// @@ -880,15 +926,17 @@ impl UnixListener { /// // ... /// } /// - /// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); - /// - /// for stream in listener.incoming() { - /// match stream { - /// Ok(stream) => { - /// thread::spawn(|| handle_client(stream)); - /// } - /// Err(err) => { - /// break; + /// fn main() -> std::io::Result<()> { + /// let listener = UnixListener::bind("/path/to/the/socket")?; + /// + /// for stream in listener.incoming() { + /// match stream { + /// Ok(stream) => { + /// thread::spawn(|| handle_client(stream)); + /// } + /// Err(err) => { + /// break; + /// } /// } /// } /// } @@ -947,15 +995,17 @@ impl<'a> IntoIterator for &'a UnixListener { /// // ... /// } /// -/// let listener = UnixListener::bind("/path/to/the/socket").unwrap(); +/// fn main() -> std::io::Result<()> { +/// let listener = UnixListener::bind("/path/to/the/socket")?; /// -/// for stream in listener.incoming() { -/// match stream { -/// Ok(stream) => { -/// thread::spawn(|| handle_client(stream)); -/// } -/// Err(err) => { -/// break; +/// for stream in listener.incoming() { +/// match stream { +/// Ok(stream) => { +/// thread::spawn(|| handle_client(stream)); +/// } +/// Err(err) => { +/// break; +/// } /// } /// } /// } @@ -986,11 +1036,13 @@ impl<'a> Iterator for Incoming<'a> { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// -/// let socket = UnixDatagram::bind("/path/to/my/socket").unwrap(); -/// socket.send_to(b"hello world", "/path/to/other/socket").unwrap(); -/// let mut buf = [0; 100]; -/// let (count, address) = socket.recv_from(&mut buf).unwrap(); -/// println!("socket {:?} sent {:?}", address, &buf[..count]); +/// fn main() -> std::io::Result<()> { +/// let socket = UnixDatagram::bind("/path/to/my/socket")?; +/// socket.send_to(b"hello world", "/path/to/other/socket")?; +/// let mut buf = [0; 100]; +/// let (count, address) = socket.recv_from(&mut buf)?; +/// println!("socket {:?} sent {:?}", address, &buf[..count]); +/// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub struct UnixDatagram(Socket); @@ -1099,14 +1151,16 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// match sock.connect("/path/to/the/socket") { - /// Ok(sock) => sock, - /// Err(e) => { - /// println!("Couldn't connect: {:?}", e); - /// return - /// } - /// }; + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// match sock.connect("/path/to/the/socket") { + /// Ok(sock) => sock, + /// Err(e) => { + /// println!("Couldn't connect: {:?}", e); + /// return + /// } + /// }; + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn connect>(&self, path: P) -> io::Result<()> { @@ -1133,9 +1187,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::bind("/path/to/the/socket")?; /// - /// let sock_copy = sock.try_clone().expect("try_clone failed"); + /// let sock_copy = sock.try_clone().expect("try_clone failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn try_clone(&self) -> io::Result { @@ -1149,9 +1205,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::bind("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::bind("/path/to/the/socket")?; /// - /// let addr = sock.local_addr().expect("Couldn't get local address"); + /// let addr = sock.local_addr().expect("Couldn't get local address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn local_addr(&self) -> io::Result { @@ -1169,10 +1227,12 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.connect("/path/to/the/socket").unwrap(); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.connect("/path/to/the/socket")?; /// - /// let addr = sock.peer_addr().expect("Couldn't get peer address"); + /// let addr = sock.peer_addr().expect("Couldn't get peer address"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn peer_addr(&self) -> io::Result { @@ -1189,11 +1249,13 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// let mut buf = vec![0; 10]; - /// match sock.recv_from(buf.as_mut_slice()) { - /// Ok((size, sender)) => println!("received {} bytes from {:?}", size, sender), - /// Err(e) => println!("recv_from function failed: {:?}", e), + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// let mut buf = vec![0; 10]; + /// match sock.recv_from(buf.as_mut_slice()) { + /// Ok((size, sender)) => println!("received {} bytes from {:?}", size, sender), + /// Err(e) => println!("recv_from function failed: {:?}", e), + /// } /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1229,9 +1291,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::bind("/path/to/the/socket").unwrap(); - /// let mut buf = vec![0; 10]; - /// sock.recv(buf.as_mut_slice()).expect("recv function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::bind("/path/to/the/socket")?; + /// let mut buf = vec![0; 10]; + /// sock.recv(buf.as_mut_slice()).expect("recv function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn recv(&self, buf: &mut [u8]) -> io::Result { @@ -1247,8 +1311,10 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.send_to(b"omelette au fromage", "/some/sock").expect("send_to function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.send_to(b"omelette au fromage", "/some/sock").expect("send_to function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn send_to>(&self, buf: &[u8], path: P) -> io::Result { @@ -1280,9 +1346,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.connect("/some/sock").expect("Couldn't connect"); - /// sock.send(b"omelette au fromage").expect("send_to function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.connect("/some/sock").expect("Couldn't connect"); + /// sock.send(b"omelette au fromage").expect("send_to function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn send(&self, buf: &[u8]) -> io::Result { @@ -1307,8 +1375,11 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_read_timeout(Some(Duration::new(1, 0))).expect("set_read_timeout function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_read_timeout(Some(Duration::new(1, 0))) + /// .expect("set_read_timeout function failed"); + /// } /// ``` /// /// An [`Err`] is returned if the zero [`Duration`] is passed to this @@ -1319,10 +1390,12 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let socket = UnixDatagram::unbound().unwrap(); - /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); - /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// fn main() -> std::io::Result<()> { + /// let socket = UnixDatagram::unbound()?; + /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); + /// let err = result.unwrap_err(); + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_read_timeout(&self, timeout: Option) -> io::Result<()> { @@ -1346,9 +1419,11 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_write_timeout(Some(Duration::new(1, 0))) - /// .expect("set_write_timeout function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_write_timeout(Some(Duration::new(1, 0))) + /// .expect("set_write_timeout function failed"); + /// } /// ``` /// /// An [`Err`] is returned if the zero [`Duration`] is passed to this @@ -1359,10 +1434,12 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let socket = UnixDatagram::unbound().unwrap(); - /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); - /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// fn main() -> std::io::Result<()> { + /// let socket = UnixDatagram::unbound()?; + /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); + /// let err = result.unwrap_err(); + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_write_timeout(&self, timeout: Option) -> io::Result<()> { @@ -1377,9 +1454,12 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_read_timeout(Some(Duration::new(1, 0))).expect("set_read_timeout function failed"); - /// assert_eq!(sock.read_timeout().unwrap(), Some(Duration::new(1, 0))); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_read_timeout(Some(Duration::new(1, 0))) + /// .expect("set_read_timeout function failed"); + /// assert_eq!(sock.read_timeout()?, Some(Duration::new(1, 0))); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn read_timeout(&self) -> io::Result> { @@ -1394,10 +1474,12 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::time::Duration; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_write_timeout(Some(Duration::new(1, 0))) - /// .expect("set_write_timeout function failed"); - /// assert_eq!(sock.write_timeout().unwrap(), Some(Duration::new(1, 0))); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_write_timeout(Some(Duration::new(1, 0))) + /// .expect("set_write_timeout function failed"); + /// assert_eq!(sock.write_timeout()?, Some(Duration::new(1, 0))); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn write_timeout(&self) -> io::Result> { @@ -1411,8 +1493,10 @@ impl UnixDatagram { /// ``` /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.set_nonblocking(true).expect("set_nonblocking function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.set_nonblocking(true).expect("set_nonblocking function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { @@ -1426,9 +1510,11 @@ impl UnixDatagram { /// ```no_run /// use std::os::unix::net::UnixDatagram; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// if let Ok(Some(err)) = sock.take_error() { - /// println!("Got error: {:?}", err); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// if let Ok(Some(err)) = sock.take_error() { + /// println!("Got error: {:?}", err); + /// } /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1448,8 +1534,10 @@ impl UnixDatagram { /// use std::os::unix::net::UnixDatagram; /// use std::net::Shutdown; /// - /// let sock = UnixDatagram::unbound().unwrap(); - /// sock.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// fn main() -> std::io::Result<()> { + /// let sock = UnixDatagram::unbound()?; + /// sock.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] pub fn shutdown(&self, how: Shutdown) -> io::Result<()> { From 3a2da7194cfe35efa2f4a5fa3415defd4335c523 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 13 Nov 2019 09:43:08 +0100 Subject: [PATCH 2/5] Return Ok(()) in docstrings in std::os::unix::net --- src/libstd/sys/unix/ext/net.rs | 55 +++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 10 deletions(-) diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index cfa157c66d102..5aafdb8241a8e 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -146,6 +146,7 @@ impl SocketAddr { /// let socket = UnixListener::bind("/tmp/sock")?; /// let addr = socket.local_addr().expect("Couldn't get local address"); /// assert_eq!(addr.is_unnamed(), false); + /// Ok(()) /// } /// ``` /// @@ -158,6 +159,7 @@ impl SocketAddr { /// let socket = UnixDatagram::unbound()?; /// let addr = socket.local_addr().expect("Couldn't get local address"); /// assert_eq!(addr.is_unnamed(), true); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -183,6 +185,7 @@ impl SocketAddr { /// let socket = UnixListener::bind("/tmp/sock")?; /// let addr = socket.local_addr().expect("Couldn't get local address"); /// assert_eq!(addr.as_pathname(), Some(Path::new("/tmp/sock"))); + /// Ok(()) /// } /// ``` /// @@ -195,6 +198,7 @@ impl SocketAddr { /// let socket = UnixDatagram::unbound()?; /// let addr = socket.local_addr().expect("Couldn't get local address"); /// assert_eq!(addr.as_pathname(), None); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -261,6 +265,7 @@ impl<'a> fmt::Display for AsciiEscaped<'a> { /// let mut response = String::new(); /// stream.read_to_string(&mut response)?; /// println!("{}", response); +/// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -349,6 +354,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock")?; /// let sock_copy = socket.try_clone().expect("Couldn't clone socket"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -366,6 +372,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock")?; /// let addr = socket.local_addr().expect("Couldn't get local address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -383,6 +390,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock")?; /// let addr = socket.peer_addr().expect("Couldn't get peer address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -424,6 +432,7 @@ impl UnixStream { /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -452,6 +461,7 @@ impl UnixStream { /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.set_write_timeout(Some(Duration::new(1, 0))) /// .expect("Couldn't set write timeout"); + /// Ok(()) /// } /// ``` /// @@ -468,6 +478,7 @@ impl UnixStream { /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -487,6 +498,7 @@ impl UnixStream { /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); /// assert_eq!(socket.read_timeout()?, Some(Duration::new(1, 0))); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -507,6 +519,7 @@ impl UnixStream { /// socket.set_write_timeout(Some(Duration::new(1, 0))) /// .expect("Couldn't set write timeout"); /// assert_eq!(socket.write_timeout()?, Some(Duration::new(1, 0))); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -524,6 +537,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.set_nonblocking(true).expect("Couldn't set nonblocking"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -543,6 +557,7 @@ impl UnixStream { /// if let Ok(Some(err)) = socket.take_error() { /// println!("Got error: {:?}", err); /// } + /// Ok(()) /// } /// ``` /// @@ -570,6 +585,7 @@ impl UnixStream { /// fn main() -> std::io::Result<()> { /// let socket = UnixStream::connect("/tmp/sock"); /// socket.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -747,6 +763,7 @@ impl IntoRawFd for net::UdpSocket { /// } /// } /// } +/// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -816,6 +833,7 @@ impl UnixListener { /// Ok((socket, addr)) => println!("Got a client: {:?}", addr), /// Err(e) => println!("accept function failed: {:?}", e), /// } + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -840,8 +858,8 @@ impl UnixListener { /// /// fn main() -> std::io::Result<()> { /// let listener = UnixListener::bind("/path/to/the/socket")?; - /// /// let listener_copy = listener.try_clone().expect("try_clone failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -858,8 +876,8 @@ impl UnixListener { /// /// fn main() -> std::io::Result<()> { /// let listener = UnixListener::bind("/path/to/the/socket")?; - /// /// let addr = listener.local_addr().expect("Couldn't get local address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -876,8 +894,8 @@ impl UnixListener { /// /// fn main() -> std::io::Result<()> { /// let listener = UnixListener::bind("/path/to/the/socket")?; - /// /// listener.set_nonblocking(true).expect("Couldn't set non blocking"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -898,6 +916,7 @@ impl UnixListener { /// if let Ok(Some(err)) = listener.take_error() { /// println!("Got error: {:?}", err); /// } + /// Ok(()) /// } /// ``` /// @@ -939,6 +958,7 @@ impl UnixListener { /// } /// } /// } + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1008,6 +1028,7 @@ impl<'a> IntoIterator for &'a UnixListener { /// } /// } /// } +/// Ok(()) /// } /// ``` #[derive(Debug)] @@ -1042,6 +1063,7 @@ impl<'a> Iterator for Incoming<'a> { /// let mut buf = [0; 100]; /// let (count, address) = socket.recv_from(&mut buf)?; /// println!("socket {:?} sent {:?}", address, &buf[..count]); +/// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1157,9 +1179,10 @@ impl UnixDatagram { /// Ok(sock) => sock, /// Err(e) => { /// println!("Couldn't connect: {:?}", e); - /// return + /// return Err(e) /// } /// }; + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1189,8 +1212,8 @@ impl UnixDatagram { /// /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::bind("/path/to/the/socket")?; - /// /// let sock_copy = sock.try_clone().expect("try_clone failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1207,8 +1230,8 @@ impl UnixDatagram { /// /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::bind("/path/to/the/socket")?; - /// /// let addr = sock.local_addr().expect("Couldn't get local address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1232,6 +1255,7 @@ impl UnixDatagram { /// sock.connect("/path/to/the/socket")?; /// /// let addr = sock.peer_addr().expect("Couldn't get peer address"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1252,10 +1276,9 @@ impl UnixDatagram { /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// let mut buf = vec![0; 10]; - /// match sock.recv_from(buf.as_mut_slice()) { - /// Ok((size, sender)) => println!("received {} bytes from {:?}", size, sender), - /// Err(e) => println!("recv_from function failed: {:?}", e), - /// } + /// let (size, sender) = sock.recv_from(buf.as_mut_slice())?; + /// println!("received {} bytes from {:?}", size, sender); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1295,6 +1318,7 @@ impl UnixDatagram { /// let sock = UnixDatagram::bind("/path/to/the/socket")?; /// let mut buf = vec![0; 10]; /// sock.recv(buf.as_mut_slice()).expect("recv function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1314,6 +1338,7 @@ impl UnixDatagram { /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// sock.send_to(b"omelette au fromage", "/some/sock").expect("send_to function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1350,6 +1375,7 @@ impl UnixDatagram { /// let sock = UnixDatagram::unbound()?; /// sock.connect("/some/sock").expect("Couldn't connect"); /// sock.send(b"omelette au fromage").expect("send_to function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1379,6 +1405,7 @@ impl UnixDatagram { /// let sock = UnixDatagram::unbound()?; /// sock.set_read_timeout(Some(Duration::new(1, 0))) /// .expect("set_read_timeout function failed"); + /// Ok(()) /// } /// ``` /// @@ -1395,6 +1422,7 @@ impl UnixDatagram { /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1423,6 +1451,7 @@ impl UnixDatagram { /// let sock = UnixDatagram::unbound()?; /// sock.set_write_timeout(Some(Duration::new(1, 0))) /// .expect("set_write_timeout function failed"); + /// Ok(()) /// } /// ``` /// @@ -1439,6 +1468,7 @@ impl UnixDatagram { /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1459,6 +1489,7 @@ impl UnixDatagram { /// sock.set_read_timeout(Some(Duration::new(1, 0))) /// .expect("set_read_timeout function failed"); /// assert_eq!(sock.read_timeout()?, Some(Duration::new(1, 0))); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1479,6 +1510,7 @@ impl UnixDatagram { /// sock.set_write_timeout(Some(Duration::new(1, 0))) /// .expect("set_write_timeout function failed"); /// assert_eq!(sock.write_timeout()?, Some(Duration::new(1, 0))); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1496,6 +1528,7 @@ impl UnixDatagram { /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// sock.set_nonblocking(true).expect("set_nonblocking function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1515,6 +1548,7 @@ impl UnixDatagram { /// if let Ok(Some(err)) = sock.take_error() { /// println!("Got error: {:?}", err); /// } + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] @@ -1537,6 +1571,7 @@ impl UnixDatagram { /// fn main() -> std::io::Result<()> { /// let sock = UnixDatagram::unbound()?; /// sock.shutdown(Shutdown::Both).expect("shutdown function failed"); + /// Ok(()) /// } /// ``` #[stable(feature = "unix_socket", since = "1.10.0")] From aff79422d8ad3c6c7a079ff393066e28298dcf3c Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 24 Nov 2019 13:56:37 +0100 Subject: [PATCH 3/5] Also fix the signature of main in std::sys::unix::ext --- src/libstd/sys/unix/ext/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/ext/mod.rs b/src/libstd/sys/unix/ext/mod.rs index 8039dcd2208cb..78a3fd05c730a 100644 --- a/src/libstd/sys/unix/ext/mod.rs +++ b/src/libstd/sys/unix/ext/mod.rs @@ -15,11 +15,13 @@ //! use std::fs::File; //! use std::os::unix::prelude::*; //! -//! fn main() { +//! fn main() -> std::io::Result<()> { //! let f = File::create("foo.txt")?; //! let fd = f.as_raw_fd(); //! //! // use fd with native unix bindings +//! +//! Ok(()) //! } //! ``` From cdfb5cb4bfff382dda24bb9106b3d0d018adb844 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 24 Nov 2019 13:57:52 +0100 Subject: [PATCH 4/5] Add missing semicolons and question marks --- src/libstd/sys/unix/ext/net.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 5aafdb8241a8e..92b62014406a4 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -431,7 +431,7 @@ impl UnixStream { /// let socket = UnixStream::connect("/tmp/sock")?; /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput); /// Ok(()) /// } /// ``` @@ -477,7 +477,7 @@ impl UnixStream { /// let socket = UdpSocket::bind("127.0.0.1:34254")?; /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput); /// Ok(()) /// } /// ``` @@ -583,7 +583,7 @@ impl UnixStream { /// use std::net::Shutdown; /// /// fn main() -> std::io::Result<()> { - /// let socket = UnixStream::connect("/tmp/sock"); + /// let socket = UnixStream::connect("/tmp/sock")?; /// socket.shutdown(Shutdown::Both).expect("shutdown function failed"); /// Ok(()) /// } @@ -1421,7 +1421,7 @@ impl UnixDatagram { /// let socket = UnixDatagram::unbound()?; /// let result = socket.set_read_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput); /// Ok(()) /// } /// ``` @@ -1467,7 +1467,7 @@ impl UnixDatagram { /// let socket = UnixDatagram::unbound()?; /// let result = socket.set_write_timeout(Some(Duration::new(0, 0))); /// let err = result.unwrap_err(); - /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput) + /// assert_eq!(err.kind(), io::ErrorKind::InvalidInput); /// Ok(()) /// } /// ``` From be18a227655b52cd49feeb61cbfe28de8f31a854 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Sun, 24 Nov 2019 15:31:28 +0100 Subject: [PATCH 5/5] Add missing main() and return value --- src/libstd/sys/unix/ext/net.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/unix/ext/net.rs b/src/libstd/sys/unix/ext/net.rs index 92b62014406a4..5177cce628c96 100644 --- a/src/libstd/sys/unix/ext/net.rs +++ b/src/libstd/sys/unix/ext/net.rs @@ -415,8 +415,11 @@ impl UnixStream { /// use std::os::unix::net::UnixStream; /// use std::time::Duration; /// - /// let socket = UnixStream::connect("/tmp/sock")?; - /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); + /// fn main() -> std::io::Result<()> { + /// let socket = UnixStream::connect("/tmp/sock")?; + /// socket.set_read_timeout(Some(Duration::new(1, 0))).expect("Couldn't set read timeout"); + /// Ok(()) + /// } /// ``` /// /// An [`Err`] is returned if the zero [`Duration`] is passed to this