Skip to content
This repository has been archived by the owner on Nov 7, 2019. It is now read-only.

add TcpStream from std conversion #78

Merged
merged 2 commits into from
Mar 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,24 @@ impl Future for ConnectFuture {
}
}

impl std::convert::TryFrom<std::net::TcpStream> for TcpStream {
type Error = io::Error;

fn try_from(stream: std::net::TcpStream) -> Result<Self, Self::Error> {
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<Self, Self::Error> {
let tcp = mio::net::TcpStream::connect(&addr)?;
Ok(TcpStream::new(tcp))
}
}

#[cfg(unix)]
mod sys {
use super::TcpStream;
Expand Down