Skip to content

Commit

Permalink
Fix up doctests and bench builds
Browse files Browse the repository at this point in the history
  • Loading branch information
bossmc committed Oct 12, 2023
1 parent 0abf7e6 commit 1ada63b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 55 deletions.
27 changes: 2 additions & 25 deletions benches/support/tokiort.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Timer for TokioTimer {
}

fn reset(&self, sleep: &mut Pin<Box<dyn Sleep>>, new_deadline: Instant) {
if let Some(sleep) = sleep.as_mut().downcast_mut_pin::<TokioSleep>() {
if let Some(sleep) = sleep.as_mut().downcast_mut_pin::<tokio::time::Sleep>() {
sleep.reset(new_deadline.into())
}
}
Expand All @@ -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::Output> {
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<T> {
#[pin]
Expand Down
34 changes: 4 additions & 30 deletions src/rt/timer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//! Provides a timer trait with timer-like functions
//!
//! Example using tokio timer:
//!
//! ```rust
//! use std::{
//! future::Future,
Expand All @@ -17,46 +18,19 @@
//!
//! impl Timer for TokioTimer {
//! fn sleep(&self, duration: Duration) -> Pin<Box<dyn Sleep>> {
//! Box::pin(TokioSleep {
//! inner: tokio::time::sleep(duration),
//! })
//! Box::pin(tokio::time::sleep(duration))
//! }
//!
//! fn sleep_until(&self, deadline: Instant) -> Pin<Box<dyn Sleep>> {
//! Box::pin(TokioSleep {
//! inner: tokio::time::sleep_until(deadline.into()),
//! })
//! Box::pin(tokio::time::sleep_until(deadline.into()))
//! }
//!
//! fn reset(&self, sleep: &mut Pin<Box<dyn Sleep>>, new_deadline: Instant) {
//! if let Some(sleep) = sleep.as_mut().downcast_mut_pin::<TokioSleep>() {
//! if let Some(sleep) = sleep.as_mut().downcast_mut_pin::<tokio::time::Sleep>() {
//! 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::Output> {
//! 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::{
Expand Down

0 comments on commit 1ada63b

Please sign in to comment.