From 8fcce957cd0f8484e5ad078fc4ada244ea463fb0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 5 Dec 2017 08:24:26 -0800 Subject: [PATCH] Rename networking constructors with `_std` This commit renames the various constructors of networking types to have a `_std` suffix instead of a smorgasboard of other suffixes, canonicalizing on `_std` as the suffix for constructors which take the libstd corresponding types. --- examples/echo-threads.rs | 2 +- examples/tinyhttp.rs | 2 +- src/net/tcp.rs | 24 +++++++++++++----------- src/net/udp/mod.rs | 4 ++-- 4 files changed, 17 insertions(+), 15 deletions(-) diff --git a/examples/echo-threads.rs b/examples/echo-threads.rs index 4869d337f..574a6be1a 100644 --- a/examples/echo-threads.rs +++ b/examples/echo-threads.rs @@ -79,7 +79,7 @@ fn worker(rx: mpsc::UnboundedReceiver) { // using the `TcpStream::from_stream` API. After that the socket is not // a `tokio::net::TcpStream` meaning it's in nonblocking mode and // ready to be used with Tokio - let socket = TcpStream::from_stream(socket, &handle) + let socket = TcpStream::from_std(socket, &handle) .expect("failed to associate TCP stream"); let addr = socket.peer_addr().expect("failed to get remote address"); diff --git a/examples/tinyhttp.rs b/examples/tinyhttp.rs index e0496928c..085bb8018 100644 --- a/examples/tinyhttp.rs +++ b/examples/tinyhttp.rs @@ -81,7 +81,7 @@ fn worker(rx: mpsc::UnboundedReceiver) { // request/response types instead of bytes. Here we'll just use our // framing defined below and then use the `send_all` helper to send the // responses back on the socket after we've processed them - let socket = future::result(TcpStream::from_stream(socket, &handle)); + let socket = future::result(TcpStream::from_std(socket, &handle)); let req = socket.and_then(|socket| { let (tx, rx) = socket.framed(Http).split(); tx.send_all(rx.and_then(respond)) diff --git a/src/net/tcp.rs b/src/net/tcp.rs index 07fae1e61..5570dd6df 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -103,10 +103,10 @@ impl TcpListener { /// will only be for the same IP version as `addr` specified. That is, if /// `addr` is an IPv4 address then all sockets accepted will be IPv4 as /// well (same for IPv6). - pub fn from_listener(listener: net::TcpListener, - addr: &SocketAddr, - handle: &Handle) -> io::Result { - let l = try!(mio::net::TcpListener::from_listener(listener, addr)); + pub fn from_std(listener: net::TcpListener, + addr: &SocketAddr, + handle: &Handle) -> io::Result { + let l = mio::net::TcpListener::from_listener(listener, addr)?; TcpListener::new(l, handle) } @@ -252,9 +252,10 @@ impl TcpStream { /// to a TCP stream ready to be used with the provided event loop handle. /// The stream returned is associated with the event loop and ready to /// perform I/O. - pub fn from_stream(stream: net::TcpStream, handle: &Handle) - -> io::Result { - let inner = try!(mio::net::TcpStream::from_stream(stream)); + pub fn from_std(stream: net::TcpStream, handle: &Handle) + -> io::Result + { + let inner = mio::net::TcpStream::from_stream(stream)?; Ok(TcpStream { io: try!(PollEvented::new(inner, handle)), }) @@ -278,10 +279,11 @@ impl TcpStream { /// loop. Note that on Windows you must `bind` a socket before it can be /// connected, so if a custom `TcpBuilder` is used it should be bound /// (perhaps to `INADDR_ANY`) before this method is called. - pub fn connect_stream(stream: net::TcpStream, - addr: &SocketAddr, - handle: &Handle) - -> Box + Send> { + pub fn connect_std(stream: net::TcpStream, + addr: &SocketAddr, + handle: &Handle) + -> Box + Send> + { let state = match mio::net::TcpStream::connect_stream(stream, addr) { Ok(tcp) => TcpStream::new(tcp, handle), Err(e) => TcpStreamNewState::Error(e), diff --git a/src/net/udp/mod.rs b/src/net/udp/mod.rs index 85ebb115a..a23ccbddd 100644 --- a/src/net/udp/mod.rs +++ b/src/net/udp/mod.rs @@ -37,8 +37,8 @@ impl UdpSocket { /// This can be used in conjunction with net2's `UdpBuilder` interface to /// configure a socket before it's handed off, such as setting options like /// `reuse_address` or binding to multiple addresses. - pub fn from_socket(socket: net::UdpSocket, - handle: &Handle) -> io::Result { + pub fn from_std(socket: net::UdpSocket, + handle: &Handle) -> io::Result { let udp = try!(mio::net::UdpSocket::from_socket(socket)); UdpSocket::new(udp, handle) }