File tree Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Expand file tree Collapse file tree 1 file changed +17
-13
lines changed Original file line number Diff line number Diff line change @@ -2,22 +2,24 @@ use std::future::Future;
22use std:: pin:: Pin ;
33use std:: time:: Duration ;
44
5+ use pin_project_lite:: pin_project;
6+
57use crate :: stream:: Stream ;
68use crate :: task:: { Context , Poll } ;
79
10+ pin_project ! {
811#[ doc( hidden) ]
912#[ allow( missing_debug_implementations) ]
10- pub struct Delay < S > {
11- stream : S ,
12- delay : futures_timer:: Delay ,
13- delay_done : bool ,
13+ pub struct Delay <S > {
14+ #[ pin]
15+ stream: S ,
16+ #[ pin]
17+ delay: futures_timer:: Delay ,
18+ delay_done: bool ,
19+ }
1420}
1521
1622impl < S > Delay < S > {
17- pin_utils:: unsafe_pinned!( stream: S ) ;
18- pin_utils:: unsafe_pinned!( delay: futures_timer:: Delay ) ;
19- pin_utils:: unsafe_unpinned!( delay_done: bool ) ;
20-
2123 pub ( super ) fn new ( stream : S , dur : Duration ) -> Self {
2224 Delay {
2325 stream,
@@ -33,12 +35,14 @@ where
3335{
3436 type Item = S :: Item ;
3537
36- fn poll_next ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
37- if !self . delay_done {
38- futures_core:: ready!( self . as_mut( ) . delay( ) . poll( cx) ) ;
39- * self . as_mut ( ) . delay_done ( ) = true ;
38+ fn poll_next ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
39+ let this = self . project ( ) ;
40+
41+ if !* this. delay_done {
42+ futures_core:: ready!( this. delay. poll( cx) ) ;
43+ * this. delay_done = true ;
4044 }
4145
42- self . as_mut ( ) . stream ( ) . poll_next ( cx)
46+ this . stream . poll_next ( cx)
4347 }
4448}
You can’t perform that action at this time.
0 commit comments