diff --git a/tokio-util/src/io/read_buf.rs b/tokio-util/src/io/read_buf.rs index ddc974bfa..7b80c4f89 100644 --- a/tokio-util/src/io/read_buf.rs +++ b/tokio-util/src/io/read_buf.rs @@ -1,8 +1,7 @@ use bytes::BufMut; -use std::future::Future; +use std::future::poll_fn; use std::io; use std::pin::Pin; -use std::task::{Context, Poll}; use tokio::io::AsyncRead; /// Read data from an `AsyncRead` into an implementer of the [`BufMut`] trait. @@ -46,20 +45,5 @@ where R: AsyncRead + Unpin, B: BufMut, { - return ReadBufFn(read, buf).await; - - struct ReadBufFn<'a, R, B>(&'a mut R, &'a mut B); - - impl<'a, R, B> Future for ReadBufFn<'a, R, B> - where - R: AsyncRead + Unpin, - B: BufMut, - { - type Output = io::Result; - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - let this = &mut *self; - crate::util::poll_read_buf(Pin::new(this.0), cx, this.1) - } - } + poll_fn(|cx| crate::util::poll_read_buf(Pin::new(read), cx, buf)).await } diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index 391dfc8c6..9fd5f1013 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -559,10 +559,6 @@ cfg_time! { } mod trace { - use std::future::Future; - use std::pin::Pin; - use std::task::{Context, Poll}; - cfg_taskdump! { pub(crate) use crate::runtime::task::trace::trace_leaf; } @@ -576,19 +572,8 @@ mod trace { } #[cfg_attr(not(feature = "sync"), allow(dead_code))] - pub(crate) fn async_trace_leaf() -> impl Future { - struct Trace; - - impl Future for Trace { - type Output = (); - - #[inline(always)] - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { - trace_leaf(cx) - } - } - - Trace + pub(crate) async fn async_trace_leaf() { + std::future::poll_fn(trace_leaf).await } } diff --git a/tokio/src/task/yield_now.rs b/tokio/src/task/yield_now.rs index 27c147967..a4832e40c 100644 --- a/tokio/src/task/yield_now.rs +++ b/tokio/src/task/yield_now.rs @@ -1,8 +1,7 @@ use crate::runtime::context; -use std::future::Future; -use std::pin::Pin; -use std::task::{ready, Context, Poll}; +use std::future::poll_fn; +use std::task::{ready, Poll}; /// Yields execution back to the Tokio runtime. /// @@ -37,28 +36,19 @@ use std::task::{ready, Context, Poll}; /// [`tokio::select!`]: macro@crate::select #[cfg_attr(docsrs, doc(cfg(feature = "rt")))] pub async fn yield_now() { - /// Yield implementation - struct YieldNow { - yielded: bool, - } + let mut yielded = false; + poll_fn(|cx| { + ready!(crate::trace::trace_leaf(cx)); - impl Future for YieldNow { - type Output = (); - - fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<()> { - ready!(crate::trace::trace_leaf(cx)); - - if self.yielded { - return Poll::Ready(()); - } - - self.yielded = true; - - context::defer(cx.waker()); - - Poll::Pending + if yielded { + return Poll::Ready(()); } - } - YieldNow { yielded: false }.await; + yielded = true; + + context::defer(cx.waker()); + + Poll::Pending + }) + .await }