@@ -8,6 +8,7 @@ use std::{
8
8
9
9
use futures_util:: Future ;
10
10
use hyper:: rt:: { Sleep , Timer } ;
11
+ use pin_project_lite:: pin_project;
11
12
12
13
#[ derive( Clone ) ]
13
14
/// An Executor that uses the tokio runtime.
@@ -29,16 +30,16 @@ where
29
30
pub struct TokioTimer ;
30
31
31
32
impl Timer for TokioTimer {
32
- fn sleep ( & self , duration : Duration ) -> Box < dyn Sleep + Unpin > {
33
- let s = tokio :: time :: sleep ( duration ) ;
34
- let hs = TokioSleep { inner : Box :: pin ( s ) } ;
35
- return Box :: new ( hs ) ;
33
+ fn sleep ( & self , duration : Duration ) -> Pin < Box < dyn Sleep > > {
34
+ Box :: pin ( TokioSleep {
35
+ inner : tokio :: time :: sleep ( duration ) ,
36
+ } )
36
37
}
37
38
38
- fn sleep_until ( & self , deadline : Instant ) -> Box < dyn Sleep + Unpin > {
39
- return Box :: new ( TokioSleep {
40
- inner : Box :: pin ( tokio:: time:: sleep_until ( deadline. into ( ) ) ) ,
41
- } ) ;
39
+ fn sleep_until ( & self , deadline : Instant ) -> Pin < Box < dyn Sleep > > {
40
+ Box :: pin ( TokioSleep {
41
+ inner : tokio:: time:: sleep_until ( deadline. into ( ) ) ,
42
+ } )
42
43
}
43
44
}
44
45
@@ -59,15 +60,18 @@ where
59
60
60
61
// Use TokioSleep to get tokio::time::Sleep to implement Unpin.
61
62
// see https://docs.rs/tokio/latest/tokio/time/struct.Sleep.html
62
- pub ( crate ) struct TokioSleep {
63
- pub ( crate ) inner : Pin < Box < tokio:: time:: Sleep > > ,
63
+ pin_project ! {
64
+ pub ( crate ) struct TokioSleep {
65
+ #[ pin]
66
+ pub ( crate ) inner: tokio:: time:: Sleep ,
67
+ }
64
68
}
65
69
66
70
impl Future for TokioSleep {
67
71
type Output = ( ) ;
68
72
69
- fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
70
- self . inner . as_mut ( ) . poll ( cx)
73
+ fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
74
+ self . project ( ) . inner . poll ( cx)
71
75
}
72
76
}
73
77
0 commit comments