From 3840ceafeeb43e9489ae7df2b0b1f54c9dd1d401 Mon Sep 17 00:00:00 2001 From: Roman Date: Tue, 6 Feb 2018 08:09:00 +0400 Subject: [PATCH] Rename TcpStreamNew -> ConnectFuture (#111) --- src/net/mod.rs | 6 +++--- src/net/tcp.rs | 42 +++++++++++++++++++++--------------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/src/net/mod.rs b/src/net/mod.rs index d579d8051..d8b2f8589 100644 --- a/src/net/mod.rs +++ b/src/net/mod.rs @@ -6,7 +6,7 @@ //! # TCP //! //! Connecting to an address, via TCP, can be done using [`TcpStream`]'s -//! [`connect`] method, which returns [`TcpStreamNew`]. `TcpStreamNew` +//! [`connect`] method, which returns [`ConnectFuture`]. `ConnectFuture` //! implements a future which returns a `TcpStream`. //! //! To listen on an address [`TcpListener`] can be used. `TcpListener`'s @@ -16,7 +16,7 @@ //! //! [`TcpStream`]: struct.TcpStream.html //! [`connect`]: struct.TcpStream.html#method.connect -//! [`TcpStreamNew`]: struct.TcpStreamNew.html +//! [`ConnectFuture`]: struct.ConnectFuture.html //! [`TcpListener`]: struct.TcpListener.html //! [incoming_method]: struct.TcpListener.html#method.incoming //! [`Incoming`]: struct.Incoming.html @@ -41,6 +41,6 @@ mod tcp; mod udp; -pub use self::tcp::{TcpStream, TcpStreamNew}; +pub use self::tcp::{TcpStream, ConnectFuture}; pub use self::tcp::{TcpListener, Incoming}; pub use self::udp::{UdpSocket, UdpCodec, UdpFramed, SendDgram, RecvDgram}; diff --git a/src/net/tcp.rs b/src/net/tcp.rs index e7d068010..bebba9674 100644 --- a/src/net/tcp.rs +++ b/src/net/tcp.rs @@ -197,13 +197,13 @@ pub struct TcpStream { /// when the stream is connected. #[must_use = "futures do nothing unless polled"] #[derive(Debug)] -pub struct TcpStreamNew { - inner: TcpStreamNewState, +pub struct ConnectFuture { + inner: ConnectFutureState, } #[must_use = "futures do nothing unless polled"] #[derive(Debug)] -enum TcpStreamNewState { +enum ConnectFutureState { Waiting(TcpStream), Error(io::Error), Empty, @@ -216,19 +216,19 @@ impl TcpStream { /// the `addr` provided. The returned future will be resolved once the /// stream has successfully connected, or it wil return an error if one /// occurs. - pub fn connect(addr: &SocketAddr) -> TcpStreamNew { + pub fn connect(addr: &SocketAddr) -> ConnectFuture { let inner = match mio::net::TcpStream::connect(addr) { Ok(tcp) => TcpStream::new(tcp, &Handle::default()), - Err(e) => TcpStreamNewState::Error(e), + Err(e) => ConnectFutureState::Error(e), }; - TcpStreamNew { inner: inner } + ConnectFuture { inner: inner } } fn new(connected_stream: mio::net::TcpStream, handle: &Handle) - -> TcpStreamNewState { + -> ConnectFutureState { match PollEvented::new(connected_stream, handle) { - Ok(io) => TcpStreamNewState::Waiting(TcpStream { io: io }), - Err(e) => TcpStreamNewState::Error(e), + Ok(io) => ConnectFutureState::Waiting(TcpStream { io: io }), + Err(e) => ConnectFutureState::Error(e), } } @@ -268,13 +268,13 @@ impl TcpStream { pub fn connect_std(stream: net::TcpStream, addr: &SocketAddr, handle: &Handle) - -> TcpStreamNew + -> ConnectFuture { let inner = match mio::net::TcpStream::connect_stream(stream, addr) { Ok(tcp) => TcpStream::new(tcp, handle), - Err(e) => TcpStreamNewState::Error(e), + Err(e) => ConnectFutureState::Error(e), }; - TcpStreamNew { inner: inner } + ConnectFuture { inner: inner } } /// Returns the local address that this stream is bound to. @@ -549,7 +549,7 @@ impl fmt::Debug for TcpStream { } } -impl Future for TcpStreamNew { +impl Future for ConnectFuture { type Item = TcpStream; type Error = io::Error; @@ -558,22 +558,22 @@ impl Future for TcpStreamNew { } } -impl Future for TcpStreamNewState { +impl Future for ConnectFutureState { type Item = TcpStream; type Error = io::Error; fn poll(&mut self) -> Poll { { let stream = match *self { - TcpStreamNewState::Waiting(ref mut s) => s, - TcpStreamNewState::Error(_) => { - let e = match mem::replace(self, TcpStreamNewState::Empty) { - TcpStreamNewState::Error(e) => e, + ConnectFutureState::Waiting(ref mut s) => s, + ConnectFutureState::Error(_) => { + let e = match mem::replace(self, ConnectFutureState::Empty) { + ConnectFutureState::Error(e) => e, _ => panic!(), }; return Err(e) } - TcpStreamNewState::Empty => panic!("can't poll TCP stream twice"), + ConnectFutureState::Empty => panic!("can't poll TCP stream twice"), }; // Once we've connected, wait for the stream to be writable as @@ -589,8 +589,8 @@ impl Future for TcpStreamNewState { return Err(e) } } - match mem::replace(self, TcpStreamNewState::Empty) { - TcpStreamNewState::Waiting(stream) => Ok(Async::Ready(stream)), + match mem::replace(self, ConnectFutureState::Empty) { + ConnectFutureState::Waiting(stream) => Ok(Async::Ready(stream)), _ => panic!(), } }