add TryFrom/From implementations (#1347)

* TryFrom<net::TcpListener> for TcpListener
* TryFrom<net::TcpStream> for TcpStream
* TryFrom<net::UdpSocket> for UdpSocket
* TryFrom<net::UnixDatagram> for UnixDatagram
* TryFrom<net::UnixListener> for UnixListener
* TryFrom<net::UnixStream> for UnixStream
* TryFrom<UnixDatagram> for mio_uds::UnixDatagram
* TryFrom<File> for io::File
* From<io::File> for File
This commit is contained in:
Taiki Endo
2019-07-24 09:26:12 -07:00
committed by Carl Lerche
parent 59bc364a0e
commit ca0e5cc670
7 changed files with 102 additions and 0 deletions
+12
View File
@@ -451,6 +451,18 @@ impl TryFrom<UdpSocket> for mio::net::UdpSocket {
}
}
impl TryFrom<net::UdpSocket> for UdpSocket {
type Error = io::Error;
/// Consumes stream, returning the tokio I/O object.
///
/// This is equivalent to
/// [`UdpSocket::from_std(stream, &Handle::default())`](UdpSocket::from_std).
fn try_from(stream: net::UdpSocket) -> Result<Self, Self::Error> {
Self::from_std(stream, &Handle::default())
}
}
impl fmt::Debug for UdpSocket {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.io.get_ref().fmt(f)