@@ -2,21 +2,23 @@ use std::pin::Pin;
22use std:: time:: Duration ;
33
44use futures_timer:: Delay ;
5+ use pin_project_lite:: pin_project;
56
67use crate :: future:: Future ;
78use 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
1621impl < 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> {
2729impl < 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