1+ use std:: future:: Future ;
12use std:: pin:: Pin ;
23
3- use crate :: future:: Future ;
4+ use pin_project_lite:: pin_project;
5+
46use crate :: stream:: Stream ;
57use crate :: task:: { Context , Poll } ;
68
7- #[ doc( hidden) ]
8- #[ allow( missing_debug_implementations) ]
9- pub struct CountFuture < S > {
10- stream : S ,
11- count : usize ,
9+ pin_project ! {
10+ #[ doc( hidden) ]
11+ #[ allow( missing_debug_implementations) ]
12+ pub struct CountFuture <S > {
13+ #[ pin]
14+ stream: S ,
15+ count: usize ,
16+ }
1217}
1318
1419impl < S > CountFuture < S > {
15- pin_utils:: unsafe_pinned!( stream: S ) ;
16- pin_utils:: unsafe_unpinned!( count: usize ) ;
17-
1820 pub ( crate ) fn new ( stream : S ) -> Self {
1921 CountFuture { stream, count : 0 }
2022 }
@@ -26,16 +28,17 @@ where
2628{
2729 type Output = usize ;
2830
29- fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
30- let next = futures_core:: ready!( self . as_mut( ) . stream( ) . poll_next( cx) ) ;
31+ fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
32+ let this = self . project ( ) ;
33+ let next = futures_core:: ready!( this. stream. poll_next( cx) ) ;
3134
3235 match next {
3336 Some ( _) => {
3437 cx. waker ( ) . wake_by_ref ( ) ;
35- * self . as_mut ( ) . count ( ) += 1 ;
38+ * this . count += 1 ;
3639 Poll :: Pending
3740 }
38- None => Poll :: Ready ( self . count ) ,
41+ None => Poll :: Ready ( * this . count ) ,
3942 }
4043 }
4144}
0 commit comments