Skip to content

Commit d97b3df

Browse files
committed
fix: Remove Pin API related unsafe code
1 parent 5c9cfb4 commit d97b3df

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/future/future/delay.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@ use std::pin::Pin;
22
use std::time::Duration;
33

44
use futures_timer::Delay;
5+
use pin_project_lite::pin_project;
56

67
use crate::future::Future;
78
use crate::task::{Context, Poll};
89

10+
pin_project! {
911
#[doc(hidden)]
1012
#[derive(Debug)]
11-
pub struct DelayFuture<F> {
12-
future: F,
13-
delay: Delay,
13+
pub struct DelayFuture<F> {
14+
#[pin]
15+
future: F,
16+
#[pin]
17+
delay: Delay,
18+
}
1419
}
1520

1621
impl<F> DelayFuture<F> {
17-
pin_utils::unsafe_pinned!(future: F);
18-
pin_utils::unsafe_pinned!(delay: Delay);
19-
2022
pub fn new(future: F, dur: Duration) -> DelayFuture<F> {
2123
let delay = Delay::new(dur);
2224

@@ -27,10 +29,12 @@ impl<F> DelayFuture<F> {
2729
impl<F: Future> Future for DelayFuture<F> {
2830
type Output = F::Output;
2931

30-
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
31-
match self.as_mut().delay().poll(cx) {
32+
fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
33+
let this = self.project();
34+
35+
match this.delay.poll(cx) {
3236
Poll::Pending => Poll::Pending,
33-
Poll::Ready(_) => match self.future().poll(cx) {
37+
Poll::Ready(_) => match this.future.poll(cx) {
3438
Poll::Ready(v) => Poll::Ready(v),
3539
Poll::Pending => Poll::Pending,
3640
},

0 commit comments

Comments
 (0)