@@ -94,6 +94,7 @@ use core::cmp;
94
94
use core:: kinds:: { Copy , Sized } ;
95
95
use core:: mem:: size_of;
96
96
use core:: mem;
97
+ use core:: ops:: FnMut ;
97
98
use core:: prelude:: { Clone , Greater , Iterator , IteratorExt , Less , None , Option } ;
98
99
use core:: prelude:: { Ord , Ordering , RawPtr , Some , range} ;
99
100
use core:: ptr;
@@ -296,7 +297,7 @@ pub trait CloneSliceAllocPrelude<T> for Sized? {
296
297
297
298
/// Partitions the vector into two vectors `(a, b)`, where all
298
299
/// elements of `a` satisfy `f` and all elements of `b` do not.
299
- fn partitioned ( & self , f: | & T | -> bool ) -> ( Vec < T > , Vec < T > ) ;
300
+ fn partitioned < F > ( & self , f : F ) -> ( Vec < T > , Vec < T > ) where F : FnMut ( & T ) -> bool ;
300
301
301
302
/// Creates an iterator that yields every possible permutation of the
302
303
/// vector in succession.
@@ -336,7 +337,7 @@ impl<T: Clone> CloneSliceAllocPrelude<T> for [T] {
336
337
337
338
338
339
#[ inline]
339
- fn partitioned ( & self , f: | & T | -> bool ) -> ( Vec < T > , Vec < T > ) {
340
+ fn partitioned < F > ( & self , mut f : F ) -> ( Vec < T > , Vec < T > ) where F : FnMut ( & T ) -> bool {
340
341
let mut lefts = Vec :: new ( ) ;
341
342
let mut rights = Vec :: new ( ) ;
342
343
@@ -361,7 +362,7 @@ impl<T: Clone> CloneSliceAllocPrelude<T> for [T] {
361
362
362
363
}
363
364
364
- fn insertion_sort < T > ( v : & mut [ T ] , compare : | & T , & T | -> Ordering ) {
365
+ fn insertion_sort < T , F > ( v : & mut [ T ] , mut compare : F ) where F : FnMut ( & T , & T ) -> Ordering {
365
366
let len = v. len ( ) as int ;
366
367
let buf_v = v. as_mut_ptr ( ) ;
367
368
@@ -403,7 +404,7 @@ fn insertion_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) {
403
404
}
404
405
}
405
406
406
- fn merge_sort < T > ( v : & mut [ T ] , compare : | & T , & T | -> Ordering ) {
407
+ fn merge_sort < T , F > ( v : & mut [ T ] , mut compare : F ) where F : FnMut ( & T , & T ) -> Ordering {
407
408
// warning: this wildly uses unsafe.
408
409
static BASE_INSERTION : uint = 32 ;
409
410
static LARGE_INSERTION : uint = 16 ;
@@ -611,7 +612,7 @@ pub trait SliceAllocPrelude<T> for Sized? {
611
612
/// v.sort_by(|a, b| b.cmp(a));
612
613
/// assert!(v == [5, 4, 3, 2, 1]);
613
614
/// ```
614
- fn sort_by ( & mut self , compare : | & T , & T | -> Ordering ) ;
615
+ fn sort_by < F > ( & mut self , compare : F ) where F : FnMut ( & T , & T ) -> Ordering ;
615
616
616
617
/// Consumes `src` and moves as many elements as it can into `self`
617
618
/// from the range [start,end).
@@ -639,7 +640,7 @@ pub trait SliceAllocPrelude<T> for Sized? {
639
640
640
641
impl < T > SliceAllocPrelude < T > for [ T ] {
641
642
#[ inline]
642
- fn sort_by ( & mut self , compare : | & T , & T | -> Ordering ) {
643
+ fn sort_by < F > ( & mut self , compare : F ) where F : FnMut ( & T , & T ) -> Ordering {
643
644
merge_sort ( self , compare)
644
645
}
645
646
0 commit comments