Move the ViewType impls into unconditional code.

Move the ViewType impls into code that is used for both the std and
polyfill configurations.
This commit is contained in:
Dan Gohman
2022-11-07 23:19:53 -08:00
parent 0e2d49ec67
commit e24daddc41
9 changed files with 79 additions and 86 deletions
+5 -5
View File
@@ -46,9 +46,9 @@ jobs:
- run: rustup target add x86_64-apple-darwin
- run: cargo check --workspace --release -vv
- run: cargo check --workspace --release -vv --all-features
- run: cargo check --workspace --release -vv --features=fs-err,os_pipe # TODO: use --all-features
- run: cargo check --workspace --release -vv --target=x86_64-apple-darwin
- run: cargo check --workspace --release -vv --target=x86_64-apple-darwin --all-features
- run: cargo check --workspace --release -vv --target=x86_64-apple-darwin --features=fs-err,os_pipe # TODO: use --all-features
check-1_48:
name: Check
@@ -102,7 +102,7 @@ jobs:
toolchain: ${{ matrix.rust }}
- run: cargo check --workspace --release -vv
- run: cargo check --workspace --release -vv --all-features
- run: cargo check --workspace --release -vv --features=fs-err,os_pipe # TODO: use --all-features
check-windows-1_48:
name: Check Windows
@@ -155,7 +155,7 @@ jobs:
- uses: ./.github/actions/install-rust
with:
toolchain: ${{ matrix.rust }}
- run: cargo test --workspace --all-features
- run: cargo test --workspace --features=fs-err,os_pipe # TODO: use --all-features
- run: cargo test --workspace --no-default-features
test_use_std:
@@ -183,7 +183,7 @@ jobs:
- uses: ./.github/actions/install-rust
with:
toolchain: ${{ matrix.rust }}
- run: cargo test --workspace --all-features
- run: cargo test --workspace --features=fs-err,os_pipe # TODO: use --all-features
- run: cargo test --workspace --no-default-features
check_nightly:
+1 -1
View File
@@ -22,7 +22,7 @@ fs-err = { version = "2.6.0", optional = true }
[target.'cfg(not(target_os = "wasi"))'.dependencies]
# Optionally depend on os_pipe to implement traits for its types for now.
os_pipe = { version = "1.0.0", optional = true }
os_pipe = { version = "1.0.0", features = ["io_safety"], optional = true }
# The following dependencies allow io-lifetimes to define impls for various
# third-party traits. This is only done in not(io_lifetimes_use_std) mode,
-16
View File
@@ -2,7 +2,6 @@
//! future, we'll prefer to have crates provide their own impls; this is
//! just a temporary measure.
use crate::views::{FilelikeViewType, SocketlikeViewType};
#[cfg(any(unix, target_os = "wasi"))]
use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
#[cfg(windows)]
@@ -101,8 +100,6 @@ impl From<OwnedHandle> for async_std::fs::File {
}
}
unsafe impl SocketlikeViewType for async_std::net::TcpStream {}
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for async_std::net::TcpStream {
#[inline]
@@ -183,8 +180,6 @@ impl From<OwnedSocket> for async_std::net::TcpStream {
}
}
unsafe impl SocketlikeViewType for async_std::net::TcpListener {}
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for async_std::net::TcpListener {
#[inline]
@@ -265,8 +260,6 @@ impl From<OwnedSocket> for async_std::net::TcpListener {
}
}
unsafe impl SocketlikeViewType for async_std::net::UdpSocket {}
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for async_std::net::UdpSocket {
#[inline]
@@ -395,9 +388,6 @@ impl AsHandle for async_std::io::Stderr {
}
}
#[cfg(unix)]
unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixStream {}
#[cfg(unix)]
impl AsFd for async_std::os::unix::net::UnixStream {
#[inline]
@@ -438,9 +428,6 @@ impl From<OwnedFd> for async_std::os::unix::net::UnixStream {
}
}
#[cfg(unix)]
unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixListener {}
#[cfg(unix)]
impl AsFd for async_std::os::unix::net::UnixListener {
#[inline]
@@ -481,9 +468,6 @@ impl From<OwnedFd> for async_std::os::unix::net::UnixListener {
}
}
#[cfg(unix)]
unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixDatagram {}
#[cfg(unix)]
impl AsFd for async_std::os::unix::net::UnixDatagram {
#[inline]
-24
View File
@@ -2,9 +2,6 @@
//! future, we'll prefer to have crates provide their own impls; this is
//! just a temporary measure.
#[cfg(unix)]
use crate::views::FilelikeViewType;
use crate::views::SocketlikeViewType;
#[cfg(any(unix, target_os = "wasi"))]
use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
#[cfg(windows)]
@@ -16,8 +13,6 @@ use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket};
unsafe impl SocketlikeViewType for mio::net::TcpStream {}
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for mio::net::TcpStream {
#[inline]
@@ -98,8 +93,6 @@ impl From<OwnedSocket> for mio::net::TcpStream {
}
}
unsafe impl SocketlikeViewType for mio::net::TcpListener {}
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for mio::net::TcpListener {
#[inline]
@@ -180,8 +173,6 @@ impl From<OwnedSocket> for mio::net::TcpListener {
}
}
unsafe impl SocketlikeViewType for mio::net::UdpSocket {}
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for mio::net::UdpSocket {
#[inline]
@@ -262,9 +253,6 @@ impl From<OwnedSocket> for mio::net::UdpSocket {
}
}
#[cfg(unix)]
unsafe impl SocketlikeViewType for mio::net::UnixDatagram {}
#[cfg(unix)]
impl AsFd for mio::net::UnixDatagram {
#[inline]
@@ -305,9 +293,6 @@ impl From<OwnedFd> for mio::net::UnixDatagram {
}
}
#[cfg(unix)]
unsafe impl SocketlikeViewType for mio::net::UnixListener {}
#[cfg(unix)]
impl AsFd for mio::net::UnixListener {
#[inline]
@@ -348,9 +333,6 @@ impl From<OwnedFd> for mio::net::UnixListener {
}
}
#[cfg(unix)]
unsafe impl SocketlikeViewType for mio::net::UnixStream {}
#[cfg(unix)]
impl AsFd for mio::net::UnixStream {
#[inline]
@@ -391,9 +373,6 @@ impl From<OwnedFd> for mio::net::UnixStream {
}
}
#[cfg(unix)]
unsafe impl FilelikeViewType for mio::unix::pipe::Receiver {}
#[cfg(unix)]
impl AsFd for mio::unix::pipe::Receiver {
#[inline]
@@ -434,9 +413,6 @@ impl From<OwnedFd> for mio::unix::pipe::Receiver {
}
}
#[cfg(unix)]
unsafe impl FilelikeViewType for mio::unix::pipe::Sender {}
#[cfg(unix)]
impl AsFd for mio::unix::pipe::Sender {
#[inline]
-5
View File
@@ -2,7 +2,6 @@
//! future, we'll prefer to have crates provide their own impls; this is
//! just a temporary measure.
use crate::views::FilelikeViewType;
#[cfg(any(unix, target_os = "wasi"))]
use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
#[cfg(windows)]
@@ -14,8 +13,6 @@ use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawHandle, FromRawHandle, IntoRawHandle};
unsafe impl FilelikeViewType for os_pipe::PipeReader {}
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for os_pipe::PipeReader {
#[inline]
@@ -96,8 +93,6 @@ impl From<OwnedHandle> for os_pipe::PipeReader {
}
}
unsafe impl FilelikeViewType for os_pipe::PipeWriter {}
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for os_pipe::PipeWriter {
#[inline]
-3
View File
@@ -2,7 +2,6 @@
//! future, we'll prefer to have crates provide their own impls; this is
//! just a temporary measure.
use crate::views::SocketlikeViewType;
#[cfg(any(unix, target_os = "wasi"))]
use crate::{AsFd, BorrowedFd, FromFd, IntoFd, OwnedFd};
#[cfg(windows)]
@@ -14,8 +13,6 @@ use std::os::wasi::io::{AsRawFd, FromRawFd, IntoRawFd};
#[cfg(windows)]
use std::os::windows::io::{AsRawSocket, FromRawSocket, IntoRawSocket};
unsafe impl SocketlikeViewType for socket2::Socket {}
#[cfg(any(unix, target_os = "wasi"))]
impl AsFd for socket2::Socket {
#[inline]
-31
View File
@@ -1,31 +0,0 @@
use crate::views::{FilelikeViewType, SocketlikeViewType};
#[cfg(any(unix, target_os = "wasi"))]
use crate::OwnedFd;
#[cfg(windows)]
use crate::{OwnedHandle, OwnedSocket};
#[cfg(any(unix, target_os = "wasi"))]
unsafe impl FilelikeViewType for OwnedFd {}
#[cfg(windows)]
unsafe impl FilelikeViewType for OwnedHandle {}
#[cfg(windows)]
unsafe impl SocketlikeViewType for OwnedSocket {}
unsafe impl FilelikeViewType for std::fs::File {}
unsafe impl SocketlikeViewType for std::net::TcpStream {}
unsafe impl SocketlikeViewType for std::net::TcpListener {}
unsafe impl SocketlikeViewType for std::net::UdpSocket {}
#[cfg(unix)]
unsafe impl SocketlikeViewType for std::os::unix::net::UnixStream {}
#[cfg(unix)]
unsafe impl SocketlikeViewType for std::os::unix::net::UnixListener {}
#[cfg(unix)]
unsafe impl SocketlikeViewType for std::os::unix::net::UnixDatagram {}
-1
View File
@@ -39,7 +39,6 @@ mod types;
#[cfg(not(io_lifetimes_use_std))]
mod impls_std;
mod impls_std_views;
#[cfg(not(io_lifetimes_use_std))]
#[cfg(any(unix, target_os = "wasi"))]
+73
View File
@@ -9,10 +9,14 @@ use crate::raw::{
AsRawFilelike, AsRawSocketlike, FromRawFilelike, FromRawSocketlike, IntoRawFilelike,
IntoRawSocketlike, RawFilelike, RawSocketlike,
};
#[cfg(any(unix, target_os = "wasi"))]
use crate::OwnedFd;
use crate::{
AsFilelike, AsSocketlike, FromFilelike, FromSocketlike, IntoFilelike, IntoSocketlike,
OwnedFilelike, OwnedSocketlike,
};
#[cfg(windows)]
use crate::{OwnedHandle, OwnedSocket};
use std::fmt;
use std::marker::PhantomData;
use std::mem::ManuallyDrop;
@@ -202,3 +206,72 @@ impl<Target: SocketlikeViewType> fmt::Debug for SocketlikeView<'_, Target> {
.finish()
}
}
#[cfg(any(unix, target_os = "wasi"))]
unsafe impl FilelikeViewType for OwnedFd {}
#[cfg(windows)]
unsafe impl FilelikeViewType for OwnedHandle {}
#[cfg(windows)]
unsafe impl SocketlikeViewType for OwnedSocket {}
unsafe impl FilelikeViewType for std::fs::File {}
unsafe impl SocketlikeViewType for std::net::TcpStream {}
unsafe impl SocketlikeViewType for std::net::TcpListener {}
unsafe impl SocketlikeViewType for std::net::UdpSocket {}
#[cfg(unix)]
unsafe impl SocketlikeViewType for std::os::unix::net::UnixStream {}
#[cfg(unix)]
unsafe impl SocketlikeViewType for std::os::unix::net::UnixListener {}
#[cfg(unix)]
unsafe impl SocketlikeViewType for std::os::unix::net::UnixDatagram {}
#[cfg(not(target_os = "wasi"))]
#[cfg(feature = "os_pipe")]
unsafe impl FilelikeViewType for os_pipe::PipeWriter {}
#[cfg(not(target_os = "wasi"))]
#[cfg(feature = "os_pipe")]
unsafe impl FilelikeViewType for os_pipe::PipeReader {}
#[cfg(not(target_os = "wasi"))]
#[cfg(feature = "socket2")]
unsafe impl SocketlikeViewType for socket2::Socket {}
#[cfg(not(target_os = "wasi"))]
#[cfg(feature = "async_std")]
unsafe impl SocketlikeViewType for async_std::net::TcpStream {}
#[cfg(not(target_os = "wasi"))]
#[cfg(feature = "async_std")]
unsafe impl SocketlikeViewType for async_std::net::TcpListener {}
#[cfg(not(target_os = "wasi"))]
#[cfg(feature = "async_std")]
unsafe impl SocketlikeViewType for async_std::net::UdpSocket {}
#[cfg(unix)]
#[cfg(feature = "async_std")]
unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixStream {}
#[cfg(unix)]
#[cfg(feature = "async_std")]
unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixListener {}
#[cfg(unix)]
#[cfg(feature = "async_std")]
unsafe impl SocketlikeViewType for async_std::os::unix::net::UnixDatagram {}
#[cfg(feature = "mio")]
unsafe impl SocketlikeViewType for mio::net::TcpStream {}
#[cfg(feature = "mio")]
unsafe impl SocketlikeViewType for mio::net::TcpListener {}
#[cfg(feature = "mio")]
unsafe impl SocketlikeViewType for mio::net::UdpSocket {}
#[cfg(unix)]
#[cfg(feature = "mio")]
unsafe impl SocketlikeViewType for mio::net::UnixDatagram {}
#[cfg(unix)]
#[cfg(feature = "mio")]
unsafe impl SocketlikeViewType for mio::net::UnixListener {}
#[cfg(unix)]
#[cfg(feature = "mio")]
unsafe impl SocketlikeViewType for mio::net::UnixStream {}
#[cfg(unix)]
#[cfg(feature = "mio")]
unsafe impl FilelikeViewType for mio::unix::pipe::Receiver {}
#[cfg(unix)]
#[cfg(feature = "mio")]
unsafe impl FilelikeViewType for mio::unix::pipe::Sender {}