@@ -2,21 +2,23 @@ use std::pin::Pin;
2
2
use std:: time:: Duration ;
3
3
4
4
use futures_timer:: Delay ;
5
+ use pin_project_lite:: pin_project;
5
6
6
7
use crate :: future:: Future ;
7
8
use crate :: task:: { Context , Poll } ;
8
9
10
+ pin_project ! {
9
11
#[ doc( hidden) ]
10
12
#[ 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
+ }
14
19
}
15
20
16
21
impl < F > DelayFuture < F > {
17
- pin_utils:: unsafe_pinned!( future: F ) ;
18
- pin_utils:: unsafe_pinned!( delay: Delay ) ;
19
-
20
22
pub fn new ( future : F , dur : Duration ) -> DelayFuture < F > {
21
23
let delay = Delay :: new ( dur) ;
22
24
@@ -27,10 +29,12 @@ impl<F> DelayFuture<F> {
27
29
impl < F : Future > Future for DelayFuture < F > {
28
30
type Output = F :: Output ;
29
31
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) {
32
36
Poll :: Pending => Poll :: Pending ,
33
- Poll :: Ready ( _) => match self . future ( ) . poll ( cx) {
37
+ Poll :: Ready ( _) => match this . future . poll ( cx) {
34
38
Poll :: Ready ( v) => Poll :: Ready ( v) ,
35
39
Poll :: Pending => Poll :: Pending ,
36
40
} ,
0 commit comments