Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bring back tokio support #7

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
8 changes: 0 additions & 8 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
*/
14 changes: 9 additions & 5 deletions src/tokio.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use io_lifetimes::{FromFilelike, IntoFilelike};
use io_lifetimes::IntoFilelike;
use std::io::IoSlice;
use std::os::fd::BorrowedFd;
use std::path::Path;
use std::pin::Pin;
use std::task::{Context, Poll};
Expand All @@ -8,7 +9,7 @@ use tokio::io::{self, AsyncRead, AsyncWrite, ReadBuf};
#[cfg(not(windows))]
use {
io_extras::os::rustix::{AsRawFd, AsRawReadWriteFd, AsReadWriteFd, RawFd},
io_lifetimes::{AsFd, BorrowedFd},
io_lifetimes::AsFd,
rustix::fs::FileTypeExt,
};
#[cfg(windows)]
Expand Down Expand Up @@ -40,7 +41,8 @@ impl TokioCharDevice {
pub async fn new<Filelike: IntoFilelike + AsyncRead + AsyncWrite>(
filelike: Filelike,
) -> io::Result<Self> {
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
sunfishcode marked this conversation as resolved.
Show resolved Hide resolved
}

async fn _new(file: File) -> io::Result<Self> {
Expand All @@ -57,7 +59,8 @@ impl TokioCharDevice {

#[cfg(windows)]
{
let file_type = winx::winapi_util::file::typ(&*file.as_filelike_view::<std::fs::File>())?;
let file_type =
winx::winapi_util::file::typ(&*file.as_filelike_view::<std::fs::File>())?;
if !file_type.is_char() {
return Err(io::Error::new(
io::ErrorKind::Other,
Expand All @@ -84,7 +87,8 @@ impl TokioCharDevice {
/// Doesn't check that the handle is valid or a character device.
#[inline]
pub unsafe fn new_unchecked<Filelike: IntoFilelike>(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.
Expand Down
6 changes: 0 additions & 6 deletions tests/null.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -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() {
Expand All @@ -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);
}
*/
6 changes: 0 additions & 6 deletions tests/tty.rs
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -25,7 +21,6 @@ fn tty() {
};
}

/*
#[cfg(feature = "async-std")]
#[async_std::test]
async fn async_std_tty() {
Expand Down Expand Up @@ -57,4 +52,3 @@ async fn tokio_tty() {
},
};
}
*/
Loading