diff --git a/Cargo.toml b/Cargo.toml index 62d5ee3..f1ca09e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,7 +11,7 @@ repository = "https://github.com/sunfishcode/char-device" exclude = ["/.github"] [dependencies] -async-std = { version = "1.10.0", optional = true } +async-std = { version = "1.10.0", optional = true, features = ["io_safety"] } tokio = { version = "1.8.1", optional = true, features = ["fs"] } io-extras = "0.18.0" io-lifetimes = { version = "2.0.0", default-features = false } @@ -23,7 +23,7 @@ rustix = { version = "1.0.0", features = ["fs"] } winx = "0.36.0" [dev-dependencies] -async-std = { version = "1.10.0", features = ["attributes"] } +async-std = { version = "1.13.0", features = ["attributes"] } tokio = { version = "1.6.0", features = ["io-util", "macros", "rt"] } [features] diff --git a/README.md b/README.md index 6ad4533..444c164 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,4 @@ This crate defines the [`CharDevice`] struct, a simple wrapper around `std::fs::File` for character devices. -Support for async-std and tokio is temporarily disabled until those crates -contain the needed implementations of the I/O safety traits. - [`CharDevice`]: https://docs.rs/char-device/latest/char_device/struct.CharDevice.html diff --git a/src/async_std.rs b/src/async_std.rs index b01bbb1..bd7d9ab 100644 --- a/src/async_std.rs +++ b/src/async_std.rs @@ -9,8 +9,8 @@ use { ::async_std::os::windows::io::{AsRawHandle, IntoRawHandle, RawHandle}, io_extras::os::windows::{ AsHandleOrSocket, AsRawHandleOrSocket, AsRawReadWriteHandleOrSocket, - AsReadWriteHandleOrSocket, BorrowedHandleOrSocket, - IntoRawHandleOrSocket, OwnedHandleOrSocket, RawHandleOrSocket, + AsReadWriteHandleOrSocket, BorrowedHandleOrSocket, IntoRawHandleOrSocket, + OwnedHandleOrSocket, RawHandleOrSocket, }, io_lifetimes::{AsFilelike, AsHandle, BorrowedHandle, OwnedHandle}, }; @@ -57,7 +57,8 @@ impl AsyncStdCharDevice { #[cfg(windows)] { - let file_type = winx::winapi_util::file::typ(&*file.as_filelike_view::())?; + let file_type = + winx::winapi_util::file::typ(&*file.as_filelike_view::())?; if !file_type.is_char() { return Err(io::Error::new( io::ErrorKind::Other, @@ -257,7 +258,7 @@ impl IntoRawHandleOrSocket for AsyncStdCharDevice { } #[cfg(windows)] -impl From for OwnedHandleOrSocket { +impl From for OwnedHandleOrSocket { #[inline] fn from(char_device: AsyncStdCharDevice) -> Self { char_device.0.into() diff --git a/src/lib.rs b/src/lib.rs index 33508f2..131e3fd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -4,22 +4,14 @@ #![cfg_attr(can_vector, feature(can_vector))] #![cfg_attr(write_all_vectored, feature(write_all_vectored))] -/* #[cfg(feature = "async-std")] mod async_std; -*/ mod char_device; -/* #[cfg(feature = "tokio")] mod tokio; -*/ -/* #[cfg(feature = "async-std")] pub use crate::async_std::AsyncStdCharDevice; -*/ pub use crate::char_device::CharDevice; -/* #[cfg(feature = "tokio")] pub use crate::tokio::TokioCharDevice; -*/ diff --git a/src/tokio.rs b/src/tokio.rs index de4ac36..2546f28 100644 --- a/src/tokio.rs +++ b/src/tokio.rs @@ -1,4 +1,4 @@ -use io_lifetimes::{FromFilelike, IntoFilelike}; +use io_lifetimes::IntoFilelike; use std::io::IoSlice; use std::path::Path; use std::pin::Pin; @@ -40,7 +40,8 @@ impl TokioCharDevice { pub async fn new( filelike: Filelike, ) -> io::Result { - Self::_new(File::from_into_filelike(filelike)).await + let std_file = std::fs::File::from(filelike.into_filelike()); + Self::_new(File::from_std(std_file)).await } async fn _new(file: File) -> io::Result { @@ -57,7 +58,8 @@ impl TokioCharDevice { #[cfg(windows)] { - let file_type = winx::winapi_util::file::typ(&*file.as_filelike_view::())?; + let file_type = + winx::winapi_util::file::typ(&*file.as_filelike_view::())?; if !file_type.is_char() { return Err(io::Error::new( io::ErrorKind::Other, @@ -84,7 +86,8 @@ impl TokioCharDevice { /// Doesn't check that the handle is valid or a character device. #[inline] pub unsafe fn new_unchecked(filelike: Filelike) -> Self { - Self(File::from_into_filelike(filelike)) + let std_file = std::fs::File::from(filelike.into_filelike()); + Self(File::from_std(std_file)) } /// Construct a new `CharDevice` which discards writes and reads nothing. diff --git a/tests/null.rs b/tests/null.rs index cf51aac..112f9e8 100644 --- a/tests/null.rs +++ b/tests/null.rs @@ -1,12 +1,8 @@ -/* #[cfg(feature = "async-std")] use char_device::AsyncStdCharDevice; -*/ use char_device::CharDevice; -/* #[cfg(feature = "tokio")] use char_device::TokioCharDevice; -*/ #[test] fn null() { @@ -19,7 +15,6 @@ fn null() { assert_eq!(char_device.read(&mut buf).unwrap(), 0); } -/* #[cfg(feature = "async-std")] #[async_std::test] async fn async_std_null() { @@ -43,4 +38,3 @@ async fn tokio_null() { let mut buf = vec![0_u8; 32]; assert_eq!(char_device.read(&mut buf).await.unwrap(), 0); } -*/ diff --git a/tests/tty.rs b/tests/tty.rs index ee6ec45..f9e7595 100644 --- a/tests/tty.rs +++ b/tests/tty.rs @@ -1,14 +1,10 @@ #![cfg(unix)] -/* #[cfg(feature = "async-std")] use char_device::AsyncStdCharDevice; -*/ use char_device::CharDevice; -/* #[cfg(feature = "tokio")] use char_device::TokioCharDevice; -*/ #[test] fn tty() { @@ -25,7 +21,6 @@ fn tty() { }; } -/* #[cfg(feature = "async-std")] #[async_std::test] async fn async_std_tty() { @@ -57,4 +52,3 @@ async fn tokio_tty() { }, }; } -*/