Skip to content

Commit

Permalink
use std::future::poll_fn (#194)
Browse files Browse the repository at this point in the history
No need for this crate to maintain its own any longer.

There was recent activity in the standard library around this,
rust-lang/rust#102737 .
  • Loading branch information
FrankReh authored Dec 3, 2022
1 parent 002c94f commit f6cb0ed
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 33 deletions.
29 changes: 0 additions & 29 deletions src/future.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
use std::future::Future;
use std::pin::Pin;
use std::task::{Context, Poll};

macro_rules! ready {
($e:expr $(,)?) => {
match $e {
Expand All @@ -10,28 +6,3 @@ macro_rules! ready {
}
};
}

#[must_use = "futures do nothing unless you `.await` or poll them"]
pub(crate) struct PollFn<F> {
f: F,
}

impl<F> Unpin for PollFn<F> {}

pub(crate) fn poll_fn<T, F>(f: F) -> PollFn<F>
where
F: FnMut(&mut Context<'_>) -> Poll<T>,
{
PollFn { f }
}

impl<T, F> Future for PollFn<F>
where
F: FnMut(&mut Context<'_>) -> Poll<T>,
{
type Output = T;

fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<T> {
(self.f)(cx)
}
}
2 changes: 1 addition & 1 deletion src/io/shared_fd.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})))
Expand Down
2 changes: 1 addition & 1 deletion tests/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
})
Expand Down
2 changes: 1 addition & 1 deletion tests/fs_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit f6cb0ed

Please sign in to comment.