@@ -2,20 +2,20 @@ use std::cmp::Ordering;
22use std:: pin:: Pin ;
33
44use crate :: future:: Future ;
5- use crate :: stream:: Stream ;
65use crate :: task:: { Context , Poll } ;
76
8- /// A future that yields the minimum item in a stream by a given comparison function.
9- #[ derive( Clone , Debug ) ]
10- pub struct MinByFuture < S : Stream , F > {
7+ #[ allow( missing_debug_implementations) ]
8+ pub struct MinByFuture < S , F , T > {
119 stream : S ,
1210 compare : F ,
13- min : Option < S :: Item > ,
11+ min : Option < T > ,
1412}
1513
16- impl < S : Stream + Unpin , F > Unpin for MinByFuture < S , F > { }
14+ impl < S , F , T > MinByFuture < S , F , T > {
15+ pin_utils:: unsafe_pinned!( stream: S ) ;
16+ pin_utils:: unsafe_unpinned!( compare: F ) ;
17+ pin_utils:: unsafe_unpinned!( min: Option <T >) ;
1718
18- impl < S : Stream + Unpin , F > MinByFuture < S , F > {
1919 pub ( super ) fn new ( stream : S , compare : F ) -> Self {
2020 MinByFuture {
2121 stream,
@@ -25,25 +25,25 @@ impl<S: Stream + Unpin, F> MinByFuture<S, F> {
2525 }
2626}
2727
28- impl < S , F > Future for MinByFuture < S , F >
28+ impl < S , F > Future for MinByFuture < S , F , S :: Item >
2929where
30- S : futures_core:: stream:: Stream + Unpin ,
30+ S : futures_core:: stream:: Stream + Unpin + Sized ,
3131 S :: Item : Copy ,
3232 F : FnMut ( & S :: Item , & S :: Item ) -> Ordering ,
3333{
3434 type Output = Option < S :: Item > ;
3535
3636 fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
37- let next = futures_core:: ready!( Pin :: new ( & mut self . stream) . poll_next( cx) ) ;
37+ let next = futures_core:: ready!( self . as_mut ( ) . stream( ) . poll_next( cx) ) ;
3838
3939 match next {
4040 Some ( new) => {
4141 cx. waker ( ) . wake_by_ref ( ) ;
42- match self . as_mut ( ) . min . take ( ) {
43- None => self . as_mut ( ) . min = Some ( new) ,
44- Some ( old) => match ( & mut self . as_mut ( ) . compare ) ( & new, & old) {
45- Ordering :: Less => self . as_mut ( ) . min = Some ( new) ,
46- _ => self . as_mut ( ) . min = Some ( old) ,
42+ match self . as_mut ( ) . min ( ) . take ( ) {
43+ None => * self . as_mut ( ) . min ( ) = Some ( new) ,
44+ Some ( old) => match ( & mut self . as_mut ( ) . compare ( ) ) ( & new, & old) {
45+ Ordering :: Less => * self . as_mut ( ) . min ( ) = Some ( new) ,
46+ _ => * self . as_mut ( ) . min ( ) = Some ( old) ,
4747 } ,
4848 }
4949 Poll :: Pending
0 commit comments