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

Commit

Permalink
add TcpStream from std conversion (#78)
Browse files Browse the repository at this point in the history
* add TcpStream from std conversion

Signed-off-by: Yoshua Wuyts <[email protected]>

* add TcpStream from SocketAddr

Signed-off-by: Yoshua Wuyts <[email protected]>
  • Loading branch information
yoshuawuyts authored Mar 26, 2019
1 parent 2d8389a commit fab9432
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -610,6 +610,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

0 comments on commit fab9432

Please sign in to comment.