From f6cb0ed0f05b99a492974e6c2c423954ec42d4ce Mon Sep 17 00:00:00 2001 From: FrankReh Date: Sat, 3 Dec 2022 17:28:50 -0500 Subject: [PATCH] use std::future::poll_fn (#194) No need for this crate to maintain its own any longer. There was recent activity in the standard library around this, https://github.com/rust-lang/rust/pull/102737 . --- src/future.rs | 29 ----------------------------- src/io/shared_fd.rs | 2 +- src/runtime/mod.rs | 2 +- tests/driver.rs | 2 +- tests/fs_file.rs | 2 +- 5 files changed, 4 insertions(+), 33 deletions(-) diff --git a/src/future.rs b/src/future.rs index f27df0eb..1f48623b 100644 --- a/src/future.rs +++ b/src/future.rs @@ -1,7 +1,3 @@ -use std::future::Future; -use std::pin::Pin; -use std::task::{Context, Poll}; - macro_rules! ready { ($e:expr $(,)?) => { match $e { @@ -10,28 +6,3 @@ macro_rules! ready { } }; } - -#[must_use = "futures do nothing unless you `.await` or poll them"] -pub(crate) struct PollFn { - f: F, -} - -impl Unpin for PollFn {} - -pub(crate) fn poll_fn(f: F) -> PollFn -where - F: FnMut(&mut Context<'_>) -> Poll, -{ - PollFn { f } -} - -impl Future for PollFn -where - F: FnMut(&mut Context<'_>) -> Poll, -{ - type Output = T; - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - (self.f)(cx) - } -} diff --git a/src/io/shared_fd.rs b/src/io/shared_fd.rs index db67c1c6..d573265f 100644 --- a/src/io/shared_fd.rs +++ b/src/io/shared_fd.rs @@ -1,5 +1,5 @@ -use crate::future::poll_fn; use crate::io::Close; +use std::future::poll_fn; use std::cell::RefCell; use std::os::unix::io::{FromRawFd, RawFd}; diff --git a/src/runtime/mod.rs b/src/runtime/mod.rs index 3524ed6a..6d672324 100644 --- a/src/runtime/mod.rs +++ b/src/runtime/mod.rs @@ -104,7 +104,7 @@ impl Runtime { tokio::pin!(future); self.rt - .block_on(self.local.run_until(crate::future::poll_fn(|cx| { + .block_on(self.local.run_until(std::future::poll_fn(|cx| { // assert!(drive.as_mut().poll(cx).is_pending()); future.as_mut().poll(cx) }))) diff --git a/tests/driver.rs b/tests/driver.rs index 7f77138c..b9bda473 100644 --- a/tests/driver.rs +++ b/tests/driver.rs @@ -133,7 +133,7 @@ async fn poll_once(future: impl std::future::Future) { pin!(future); - future::poll_fn(|cx| { + std::future::poll_fn(|cx| { assert!(future.as_mut().poll(cx).is_pending()); Poll::Ready(()) }) diff --git a/tests/fs_file.rs b/tests/fs_file.rs index 051d261e..d2ffa8ec 100644 --- a/tests/fs_file.rs +++ b/tests/fs_file.rs @@ -287,7 +287,7 @@ fn tempfile() -> NamedTempFile { } async fn poll_once(future: impl std::future::Future) { - use future::poll_fn; + use std::future::poll_fn; // use std::future::Future; use std::task::Poll; use tokio::pin;