Implement TryFrom to transform various I/O primitives into their mio counterparts (#1158)

* `TryFrom<TcpListener> for mio::net::TcpListener`
* `TryFrom<TcpStream> for mio::net::TcpStream`
* `TryFrom<UdpSocket> for mio::net::UdpSocket`
* `TryFrom<UnixListener> for mio_uds::UnixListener`
* `TryFrom<UnixStream> for mio_uds::UnixStream`
This commit is contained in:
Denis
2019-06-26 08:51:38 -07:00
committed by Carl Lerche
parent 3cc33dca7c
commit dd126c2333
5 changed files with 65 additions and 0 deletions
+13
View File
@@ -1,6 +1,7 @@
use super::{RecvDgram, SendDgram};
use futures::{try_ready, Async, Poll};
use mio;
use std::convert::TryFrom;
use std::fmt;
use std::io;
use std::net::{self, Ipv4Addr, Ipv6Addr, SocketAddr};
@@ -418,6 +419,18 @@ impl UdpSocket {
}
}
impl TryFrom<UdpSocket> for mio::net::UdpSocket {
type Error = io::Error;
/// Consumes value, returning the mio I/O object.
///
/// See [`tokio_reactor::PollEvented::into_inner`] for more details about
/// resource deregistration that happens during the call.
fn try_from(value: UdpSocket) -> Result<Self, Self::Error> {
value.io.into_inner()
}
}
impl fmt::Debug for UdpSocket {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.io.get_ref().fmt(f)