mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-26 00:00:16 +02:00
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:
@@ -18,6 +18,7 @@ pub use self::seek::SeekFuture;
|
||||
|
||||
use tokio_io::{AsyncRead, AsyncWrite};
|
||||
|
||||
use std::convert::TryFrom;
|
||||
use std::fs::{File as StdFile, Metadata, Permissions};
|
||||
use std::io::{self, Read, Seek, Write};
|
||||
use std::path::Path;
|
||||
@@ -536,3 +537,19 @@ impl Drop for File {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<StdFile> for File {
|
||||
fn from(std: StdFile) -> Self {
|
||||
Self::from_std(std)
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<File> for StdFile {
|
||||
type Error = io::Error;
|
||||
|
||||
fn try_from(mut file: File) -> Result<Self, Self::Error> {
|
||||
file.std
|
||||
.take()
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "`File` instance already shutdown"))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user