File tree 1 file changed +9
-10
lines changed
1 file changed +9
-10
lines changed Original file line number Diff line number Diff line change @@ -710,18 +710,17 @@ where
710
710
return None ;
711
711
}
712
712
713
- let idx_opt = {
714
- // work around borrowck limitations
715
- let pred = & mut self . pred ;
716
- self . v . iter ( ) . position ( |x| ( * pred) ( x) )
717
- } ;
718
- match idx_opt {
713
+ match self . v . iter ( ) . position ( |x| ( self . pred ) ( x) ) {
719
714
None => self . finish ( ) ,
720
715
Some ( idx) => {
721
- let tmp = mem:: replace ( & mut self . v , & mut [ ] ) ;
722
- let ( head, tail) = tmp. split_at_mut ( idx) ;
723
- self . v = & mut tail[ 1 ..] ;
724
- Some ( head)
716
+ let tmp = mem:: take ( & mut self . v ) ;
717
+ // idx is the index of the element we are splitting on. We want to set self to the
718
+ // region after idx, and return the subslice before and not including idx.
719
+ // So first we split after idx
720
+ let ( head, tail) = tmp. split_at_mut ( idx + 1 ) ;
721
+ self . v = tail;
722
+ // Then return the subslice up to but not including the found element
723
+ Some ( & mut head[ ..idx] )
725
724
}
726
725
}
727
726
}
You can’t perform that action at this time.
0 commit comments