From 1ada63b9b043635bff0f4a89fa8b1088a6d4a879 Mon Sep 17 00:00:00 2001 From: Andy Caldwell Date: Thu, 12 Oct 2023 20:23:20 +0100 Subject: [PATCH] Fix up doctests and bench builds --- benches/support/tokiort.rs | 27 ++------------------------- src/rt/timer.rs | 34 ++++------------------------------ 2 files changed, 6 insertions(+), 55 deletions(-) diff --git a/benches/support/tokiort.rs b/benches/support/tokiort.rs index b6f32ff733..e3a898c1e8 100644 --- a/benches/support/tokiort.rs +++ b/benches/support/tokiort.rs @@ -38,7 +38,7 @@ impl Timer for TokioTimer { } fn reset(&self, sleep: &mut Pin>, new_deadline: Instant) { - if let Some(sleep) = sleep.as_mut().downcast_mut_pin::() { + if let Some(sleep) = sleep.as_mut().downcast_mut_pin::() { sleep.reset(new_deadline.into()) } } @@ -59,30 +59,7 @@ where } } -// Use TokioSleep to get tokio::time::Sleep to implement Unpin. -// see https://docs.rs/tokio/latest/tokio/time/struct.Sleep.html -pin_project! { - pub(crate) struct TokioSleep { - #[pin] - pub(crate) inner: tokio::time::Sleep, - } -} - -impl Future for TokioSleep { - type Output = (); - - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { - self.project().inner.poll(cx) - } -} - -impl TokioSleep { - pub fn reset(self: Pin<&mut Self>, deadline: Instant) { - self.project().inner.as_mut().reset(deadline.into()); - } -} - -pin_project! { +pin_project_lite::pin_project! { #[derive(Debug)] pub struct TokioIo { #[pin] diff --git a/src/rt/timer.rs b/src/rt/timer.rs index c79f3bfc15..e52e2f6f26 100644 --- a/src/rt/timer.rs +++ b/src/rt/timer.rs @@ -1,6 +1,7 @@ //! Provides a timer trait with timer-like functions //! //! Example using tokio timer: +//! //! ```rust //! use std::{ //! future::Future, @@ -17,46 +18,19 @@ //! //! impl Timer for TokioTimer { //! fn sleep(&self, duration: Duration) -> Pin> { -//! Box::pin(TokioSleep { -//! inner: tokio::time::sleep(duration), -//! }) +//! Box::pin(tokio::time::sleep(duration)) //! } //! //! fn sleep_until(&self, deadline: Instant) -> Pin> { -//! Box::pin(TokioSleep { -//! inner: tokio::time::sleep_until(deadline.into()), -//! }) +//! Box::pin(tokio::time::sleep_until(deadline.into())) //! } //! //! fn reset(&self, sleep: &mut Pin>, new_deadline: Instant) { -//! if let Some(sleep) = sleep.as_mut().downcast_mut_pin::() { +//! if let Some(sleep) = sleep.as_mut().downcast_mut_pin::() { //! sleep.reset(new_deadline.into()) //! } //! } //! } -//! -//! pin_project! { -//! pub(crate) struct TokioSleep { -//! #[pin] -//! pub(crate) inner: tokio::time::Sleep, -//! } -//! } -//! -//! impl Future for TokioSleep { -//! type Output = (); -//! -//! fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { -//! self.project().inner.poll(cx) -//! } -//! } -//! -//! impl Sleep for TokioSleep {} -//! -//! impl TokioSleep { -//! pub fn reset(self: Pin<&mut Self>, deadline: Instant) { -//! self.project().inner.as_mut().reset(deadline.into()); -//! } -//! } //! ```` use std::{