89
89
90
90
use alloc:: boxed:: Box ;
91
91
use core:: cmp;
92
+ use core:: kinds:: Sized ;
92
93
use core:: mem:: size_of;
93
94
use core:: mem;
94
95
use core:: prelude:: { Clone , Collection , Greater , Iterator , Less , None , Option } ;
@@ -109,7 +110,7 @@ pub use core::slice::{Found, NotFound};
109
110
// Functional utilities
110
111
111
112
#[ allow( missing_doc) ]
112
- pub trait VectorVector < T > {
113
+ pub trait VectorVector < T > for Sized ? {
113
114
// FIXME #5898: calling these .concat and .connect conflicts with
114
115
// StrVector::con{cat,nect}, since they have generic contents.
115
116
/// Flattens a vector of vectors of `T` into a single `Vec<T>`.
@@ -119,7 +120,7 @@ pub trait VectorVector<T> {
119
120
fn connect_vec ( & self , sep : & T ) -> Vec < T > ;
120
121
}
121
122
122
- impl < ' a , T : Clone , V : AsSlice < T > > VectorVector < T > for & ' a [ V ] {
123
+ impl < T : Clone , V : AsSlice < T > > VectorVector < T > for [ V ] {
123
124
fn concat_vec ( & self ) -> Vec < T > {
124
125
let size = self . iter ( ) . fold ( 0 u, |acc, v| acc + v. as_slice ( ) . len ( ) ) ;
125
126
let mut result = Vec :: with_capacity ( size) ;
@@ -267,17 +268,17 @@ impl<T: Clone> Iterator<Vec<T>> for Permutations<T> {
267
268
}
268
269
269
270
/// Extension methods for vector slices with cloneable elements
270
- pub trait CloneableVector < T > {
271
+ pub trait CloneableVector < T > for Sized ? {
271
272
/// Copies `self` into a new `Vec`.
272
273
fn to_vec ( & self ) -> Vec < T > ;
273
274
}
274
275
275
- impl < ' a , T : Clone > CloneableVector < T > for & ' a [ T ] {
276
+ impl < T : Clone > CloneableVector < T > for [ T ] {
276
277
/// Returns a copy of `v`.
277
278
#[ inline]
278
279
fn to_vec ( & self ) -> Vec < T > {
279
280
let mut vector = Vec :: with_capacity ( self . len ( ) ) ;
280
- vector. push_all ( * self ) ;
281
+ vector. push_all ( self ) ;
281
282
vector
282
283
}
283
284
}
@@ -300,7 +301,7 @@ impl<T> BoxedSlice<T> for Box<[T]> {
300
301
}
301
302
302
303
/// Extension methods for vectors containing `Clone` elements.
303
- pub trait ImmutableCloneableVector < T > {
304
+ pub trait ImmutableCloneableVector < T > for Sized ? {
304
305
/// Partitions the vector into two vectors `(a, b)`, where all
305
306
/// elements of `a` satisfy `f` and all elements of `b` do not.
306
307
fn partitioned ( & self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) ;
@@ -329,10 +330,10 @@ pub trait ImmutableCloneableVector<T> {
329
330
/// assert_eq!(Some(vec![1i, 3, 2]), perms.next());
330
331
/// assert_eq!(Some(vec![3i, 1, 2]), perms.next());
331
332
/// ```
332
- fn permutations ( self ) -> Permutations < T > ;
333
+ fn permutations ( & self ) -> Permutations < T > ;
333
334
}
334
335
335
- impl < ' a , T : Clone > ImmutableCloneableVector < T > for & ' a [ T ] {
336
+ impl < T : Clone > ImmutableCloneableVector < T > for [ T ] {
336
337
#[ inline]
337
338
fn partitioned ( & self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) {
338
339
let mut lefts = Vec :: new ( ) ;
@@ -350,7 +351,7 @@ impl<'a,T:Clone> ImmutableCloneableVector<T> for &'a [T] {
350
351
}
351
352
352
353
/// Returns an iterator over all permutations of a vector.
353
- fn permutations ( self ) -> Permutations < T > {
354
+ fn permutations ( & self ) -> Permutations < T > {
354
355
Permutations {
355
356
swaps : ElementSwaps :: new ( self . len ( ) ) ,
356
357
v : self . to_vec ( ) ,
@@ -564,7 +565,7 @@ fn merge_sort<T>(v: &mut [T], compare: |&T, &T| -> Ordering) {
564
565
565
566
/// Extension methods for vectors such that their elements are
566
567
/// mutable.
567
- pub trait MutableSliceAllocating < ' a , T > {
568
+ pub trait MutableSliceAllocating < T > for Sized ? {
568
569
/// Sorts the slice, in place, using `compare` to compare
569
570
/// elements.
570
571
///
@@ -582,7 +583,7 @@ pub trait MutableSliceAllocating<'a, T> {
582
583
/// v.sort_by(|a, b| b.cmp(a));
583
584
/// assert!(v == [5, 4, 3, 2, 1]);
584
585
/// ```
585
- fn sort_by ( self , compare : |& T , & T | -> Ordering ) ;
586
+ fn sort_by ( & mut self , compare : |& T , & T | -> Ordering ) ;
586
587
587
588
/// Consumes `src` and moves as many elements as it can into `self`
588
589
/// from the range [start,end).
@@ -605,17 +606,17 @@ pub trait MutableSliceAllocating<'a, T> {
605
606
/// assert_eq!(num_moved, 3);
606
607
/// assert!(a == [6i, 7, 8, 4, 5]);
607
608
/// ```
608
- fn move_from ( self , src : Vec < T > , start : uint , end : uint ) -> uint ;
609
+ fn move_from ( & mut self , src : Vec < T > , start : uint , end : uint ) -> uint ;
609
610
}
610
611
611
- impl < ' a , T > MutableSliceAllocating < ' a , T > for & ' a mut [ T ] {
612
+ impl < T > MutableSliceAllocating < T > for [ T ] {
612
613
#[ inline]
613
- fn sort_by ( self , compare : |& T , & T | -> Ordering ) {
614
+ fn sort_by ( & mut self , compare : |& T , & T | -> Ordering ) {
614
615
merge_sort ( self , compare)
615
616
}
616
617
617
618
#[ inline]
618
- fn move_from ( self , mut src : Vec < T > , start : uint , end : uint ) -> uint {
619
+ fn move_from ( & mut self , mut src : Vec < T > , start : uint , end : uint ) -> uint {
619
620
for ( a, b) in self . iter_mut ( ) . zip ( src[ mut start..end] . iter_mut ( ) ) {
620
621
mem:: swap ( a, b) ;
621
622
}
@@ -625,7 +626,7 @@ impl<'a,T> MutableSliceAllocating<'a, T> for &'a mut [T] {
625
626
626
627
/// Methods for mutable vectors with orderable elements, such as
627
628
/// in-place sorting.
628
- pub trait MutableOrdSlice < T > {
629
+ pub trait MutableOrdSlice < T > for Sized ? {
629
630
/// Sorts the slice, in place.
630
631
///
631
632
/// This is equivalent to `self.sort_by(|a, b| a.cmp(b))`.
@@ -638,7 +639,7 @@ pub trait MutableOrdSlice<T> {
638
639
/// v.sort();
639
640
/// assert!(v == [-5i, -3, 1, 2, 4]);
640
641
/// ```
641
- fn sort ( self ) ;
642
+ fn sort ( & mut self ) ;
642
643
643
644
/// Mutates the slice to the next lexicographic permutation.
644
645
///
@@ -656,7 +657,7 @@ pub trait MutableOrdSlice<T> {
656
657
/// let b: &mut [_] = &mut [1i, 0, 2];
657
658
/// assert!(v == b);
658
659
/// ```
659
- fn next_permutation ( self ) -> bool ;
660
+ fn next_permutation ( & mut self ) -> bool ;
660
661
661
662
/// Mutates the slice to the previous lexicographic permutation.
662
663
///
@@ -674,16 +675,16 @@ pub trait MutableOrdSlice<T> {
674
675
/// let b: &mut [_] = &mut [0i, 1, 2];
675
676
/// assert!(v == b);
676
677
/// ```
677
- fn prev_permutation ( self ) -> bool ;
678
+ fn prev_permutation ( & mut self ) -> bool ;
678
679
}
679
680
680
- impl < ' a , T : Ord > MutableOrdSlice < T > for & ' a mut [ T ] {
681
+ impl < T : Ord > MutableOrdSlice < T > for [ T ] {
681
682
#[ inline]
682
- fn sort ( self ) {
683
- self . sort_by ( |a, b| a. cmp ( b) )
683
+ fn sort ( & mut self ) {
684
+ self . sort_by ( |a, b| a. cmp ( b) )
684
685
}
685
686
686
- fn next_permutation ( self ) -> bool {
687
+ fn next_permutation ( & mut self ) -> bool {
687
688
// These cases only have 1 permutation each, so we can't do anything.
688
689
if self . len ( ) < 2 { return false ; }
689
690
@@ -713,7 +714,7 @@ impl<'a, T: Ord> MutableOrdSlice<T> for &'a mut [T] {
713
714
true
714
715
}
715
716
716
- fn prev_permutation ( self ) -> bool {
717
+ fn prev_permutation ( & mut self ) -> bool {
717
718
// These cases only have 1 permutation each, so we can't do anything.
718
719
if self . len ( ) < 2 { return false ; }
719
720
0 commit comments