Add TryFrom impls

This commit is contained in:
Stjepan Glavina 2020-09-14 17:48:45 +02:00
parent f6aa1c66e4
commit 74b65b1180
1 changed files with 52 additions and 0 deletions

View File

@ -55,6 +55,7 @@
#![warn(missing_docs, missing_debug_implementations, rust_2018_idioms)]
use std::convert::TryFrom;
use std::future::Future;
use std::io::{self, IoSlice, IoSliceMut, Read, Write};
use std::mem::ManuallyDrop;
@ -875,6 +876,14 @@ impl Async<TcpListener> {
}
}
impl TryFrom<std::net::TcpListener> for Async<std::net::TcpListener> {
type Error = io::Error;
fn try_from(listener: std::net::TcpListener) -> io::Result<Self> {
Async::new(listener)
}
}
impl Async<TcpStream> {
/// Creates a TCP connection to the specified address.
///
@ -956,6 +965,14 @@ impl Async<TcpStream> {
}
}
impl TryFrom<std::net::TcpStream> for Async<std::net::TcpStream> {
type Error = io::Error;
fn try_from(stream: std::net::TcpStream) -> io::Result<Self> {
Async::new(stream)
}
}
impl Async<UdpSocket> {
/// Creates a UDP socket bound to the specified address.
///
@ -1131,6 +1148,14 @@ impl Async<UdpSocket> {
}
}
impl TryFrom<std::net::UdpSocket> for Async<std::net::UdpSocket> {
type Error = io::Error;
fn try_from(socket: std::net::UdpSocket) -> io::Result<Self> {
Async::new(socket)
}
}
#[cfg(unix)]
impl Async<UnixListener> {
/// Creates a UDS listener bound to the specified path.
@ -1203,6 +1228,15 @@ impl Async<UnixListener> {
}
}
#[cfg(unix)]
impl TryFrom<std::os::unix::net::UnixListener> for Async<std::os::unix::net::UnixListener> {
type Error = io::Error;
fn try_from(listener: std::os::unix::net::UnixListener) -> io::Result<Self> {
Async::new(listener)
}
}
#[cfg(unix)]
impl Async<UnixStream> {
/// Creates a UDS stream connected to the specified path.
@ -1261,6 +1295,15 @@ impl Async<UnixStream> {
}
}
#[cfg(unix)]
impl TryFrom<std::os::unix::net::UnixStream> for Async<std::os::unix::net::UnixStream> {
type Error = io::Error;
fn try_from(stream: std::os::unix::net::UnixStream) -> io::Result<Self> {
Async::new(stream)
}
}
#[cfg(unix)]
impl Async<UnixDatagram> {
/// Creates a UDS datagram socket bound to the specified path.
@ -1407,6 +1450,15 @@ impl Async<UnixDatagram> {
}
}
#[cfg(unix)]
impl TryFrom<std::os::unix::net::UnixDatagram> for Async<std::os::unix::net::UnixDatagram> {
type Error = io::Error;
fn try_from(socket: std::os::unix::net::UnixDatagram) -> io::Result<Self> {
Async::new(socket)
}
}
/// Polls a future once.
fn poll_future<T>(cx: &mut Context<'_>, fut: impl Future<Output = T>) -> Poll<T> {
pin!(fut);