File tree 1 file changed +4
-3
lines changed
1 file changed +4
-3
lines changed Original file line number Diff line number Diff line change @@ -2949,7 +2949,7 @@ pub trait Itertools: Iterator {
2949
2949
/// itertools::assert_equal(five_smallest, 0..5);
2950
2950
/// ```
2951
2951
#[ cfg( feature = "use_alloc" ) ]
2952
- fn k_smallest ( mut self , k : usize ) -> VecIntoIter < Self :: Item >
2952
+ fn k_smallest ( self , k : usize ) -> VecIntoIter < Self :: Item >
2953
2953
where
2954
2954
Self : Sized ,
2955
2955
Self :: Item : Ord ,
@@ -2963,9 +2963,10 @@ pub trait Itertools: Iterator {
2963
2963
return Vec :: new ( ) . into_iter ( ) ;
2964
2964
}
2965
2965
2966
- let mut heap = self . by_ref ( ) . take ( k) . collect :: < BinaryHeap < _ > > ( ) ;
2966
+ let mut iter = self . fuse ( ) ;
2967
+ let mut heap: BinaryHeap < _ > = iter. by_ref ( ) . take ( k) . collect ( ) ;
2967
2968
2968
- self . for_each ( |i| {
2969
+ iter . for_each ( |i| {
2969
2970
debug_assert_eq ! ( heap. len( ) , k) ;
2970
2971
// Equivalent to heap.push(min(i, heap.pop())) but more efficient.
2971
2972
// This should be done with a single `.peek_mut().unwrap()` but
You can’t perform that action at this time.
0 commit comments