Skip to content

Commit

Permalink
Remove dependency on futures-lite
Browse files Browse the repository at this point in the history
futures-lite is only used for a convenience macro and it's easy enough
to inline it. This avoids pulling in futures-lite dependencies like
fastrand and waker-fn, reducing the need for security updates.

Separately, tokio's net feature is not needed, so remove it.

Fixes polachok#3
  • Loading branch information
chadaustin committed Nov 19, 2024
1 parent 9c7547f commit c813e80
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@ repository = "https://github.com/polachok/tokio-eventfd"
license = "MIT"

[dependencies]
tokio = { version = "1.0", features = ["net"] }
futures-lite = "1.11"
tokio = { version = "1.0", features = [] }
libc = "0.2"

[dev-dependencies]
Expand Down
11 changes: 8 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
use std::pin::Pin;
use std::task::{Context, Poll};

use futures_lite::ready;
use tokio::io::unix::AsyncFd;
use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

Expand Down Expand Up @@ -115,7 +114,10 @@ impl AsyncRead for EventFd {
buf: &mut ReadBuf<'_>,
) -> Poll<Result<()>> {
loop {
let mut guard = ready!(self.0.poll_read_ready(cx))?;
let mut guard = match self.0.poll_read_ready(cx) {
Poll::Ready(t) => t?,
Poll::Pending => return Poll::Pending,
};

let unfilled = buf.initialize_unfilled();
match guard.try_io(|inner| inner.get_ref().read(unfilled)) {
Expand All @@ -137,7 +139,10 @@ impl AsyncWrite for EventFd {
buf: &[u8],
) -> Poll<io::Result<usize>> {
loop {
let mut guard = ready!(self.0.poll_write_ready(cx))?;
let mut guard = match self.0.poll_write_ready(cx) {
Poll::Ready(t) => t?,
Poll::Pending => return Poll::Pending,
};

match guard.try_io(|inner| inner.get_ref().write(buf)) {
Ok(result) => return Poll::Ready(result),
Expand Down

0 comments on commit c813e80

Please sign in to comment.