mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-09-09 00:00:08 +02:00
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:
@@ -2,6 +2,7 @@
|
||||
use super::incoming::Incoming;
|
||||
use super::TcpStream;
|
||||
use mio;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::io;
|
||||
use std::net::{self, SocketAddr};
|
||||
@@ -313,6 +314,18 @@ impl TcpListener {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<TcpListener> for mio::net::TcpListener {
|
||||
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: TcpListener) -> Result<Self, Self::Error> {
|
||||
value.io.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TcpListener {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.io.get_ref().fmt(f)
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use bytes::{Buf, BufMut};
|
||||
use iovec::IoVec;
|
||||
use mio;
|
||||
use std::convert::TryFrom;
|
||||
use std::fmt;
|
||||
use std::future::Future;
|
||||
use std::io;
|
||||
@@ -709,6 +710,18 @@ impl TcpStream {
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<TcpStream> for mio::net::TcpStream {
|
||||
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: TcpStream) -> Result<Self, Self::Error> {
|
||||
value.io.into_inner()
|
||||
}
|
||||
}
|
||||
|
||||
// ===== impl Read / Write =====
|
||||
|
||||
impl AsyncRead for TcpStream {
|
||||
|
||||
Reference in New Issue
Block a user