diff --git a/src/tcp/stream.rs b/src/tcp/stream.rs index 226754d2..9dae056c 100644 --- a/src/tcp/stream.rs +++ b/src/tcp/stream.rs @@ -599,6 +599,24 @@ impl Future for ConnectFuture { } } +impl std::convert::TryFrom for TcpStream { + type Error = io::Error; + + fn try_from(stream: std::net::TcpStream) -> Result { + let tcp = mio::net::TcpStream::from_stream(stream)?; + Ok(TcpStream::new(tcp)) + } +} + +impl std::convert::TryFrom<&std::net::SocketAddr> for TcpStream { + type Error = io::Error; + + fn try_from(addr: &std::net::SocketAddr) -> Result { + let tcp = mio::net::TcpStream::connect(&addr)?; + Ok(TcpStream::new(tcp)) + } +} + #[cfg(unix)] mod sys { use super::TcpStream;