@@ -99,6 +99,7 @@ use slice::{Items, MutItems};
9999/// to use `Vec::with_capacity` whenever possible to specify how big the vector
100100/// is expected to get.
101101#[ unsafe_no_drop_flag]
102+ #[ stable]
102103pub struct Vec < T > {
103104 len : uint ,
104105 cap : uint ,
@@ -116,6 +117,7 @@ impl<T> Vec<T> {
116117 /// let mut vec: Vec<int> = Vec::new();
117118 /// ```
118119 #[ inline]
120+ #[ stable]
119121 pub fn new ( ) -> Vec < T > {
120122 // We want ptr to never be NULL so instead we set it to some arbitrary
121123 // non-null value which is fine since we never call deallocate on the ptr
@@ -152,6 +154,7 @@ impl<T> Vec<T> {
152154 /// vec.push(11);
153155 /// ```
154156 #[ inline]
157+ #[ stable]
155158 pub fn with_capacity ( capacity : uint ) -> Vec < T > {
156159 if mem:: size_of :: < T > ( ) == 0 {
157160 Vec { len : 0 , cap : uint:: MAX , ptr : EMPTY as * mut T }
@@ -177,6 +180,8 @@ impl<T> Vec<T> {
177180 /// assert_eq!(vec, vec![0, 2, 4]);
178181 /// ```
179182 #[ inline]
183+ #[ unstable = "the naming is uncertain as well as this migrating to unboxed \
184+ closures in the future"]
180185 pub fn from_fn ( length : uint , op: |uint| -> T ) -> Vec < T > {
181186 unsafe {
182187 let mut xs = Vec :: with_capacity ( length) ;
@@ -229,6 +234,7 @@ impl<T> Vec<T> {
229234 /// }
230235 /// }
231236 /// ```
237+ #[ experimental]
232238 pub unsafe fn from_raw_parts ( length : uint , capacity : uint ,
233239 ptr : * mut T ) -> Vec < T > {
234240 Vec { len : length, cap : capacity, ptr : ptr }
@@ -249,6 +255,7 @@ impl<T> Vec<T> {
249255 /// assert_eq!(odd, vec![1, 3]);
250256 /// ```
251257 #[ inline]
258+ #[ experimental]
252259 pub fn partition ( self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) {
253260 let mut lefts = Vec :: new ( ) ;
254261 let mut rights = Vec :: new ( ) ;
@@ -277,6 +284,7 @@ impl<T: Clone> Vec<T> {
277284 /// assert_eq!(vec, vec![1, 2, 3, 4]);
278285 /// ```
279286 #[ inline]
287+ #[ deprecated = "this function has been deprecated in favor of extend()" ]
280288 pub fn append ( mut self , second : & [ T ] ) -> Vec < T > {
281289 self . push_all ( second) ;
282290 self
@@ -291,6 +299,7 @@ impl<T: Clone> Vec<T> {
291299 /// let vec = Vec::from_slice(slice);
292300 /// ```
293301 #[ inline]
302+ #[ deprecated = "this function has been deprecated in favor of to_vec()" ]
294303 pub fn from_slice ( values : & [ T ] ) -> Vec < T > {
295304 let mut vector = Vec :: new ( ) ;
296305 vector. push_all ( values) ;
@@ -307,6 +316,7 @@ impl<T: Clone> Vec<T> {
307316 /// println!("{}", vec); // prints [hi, hi, hi]
308317 /// ```
309318 #[ inline]
319+ #[ unstable = "this functionality may become more generic over all collections" ]
310320 pub fn from_elem ( length : uint , value : T ) -> Vec < T > {
311321 unsafe {
312322 let mut xs = Vec :: with_capacity ( length) ;
@@ -333,6 +343,7 @@ impl<T: Clone> Vec<T> {
333343 /// assert_eq!(vec, vec![1, 2, 3, 4]);
334344 /// ```
335345 #[ inline]
346+ #[ experimental]
336347 pub fn push_all ( & mut self , other : & [ T ] ) {
337348 self . reserve_additional ( other. len ( ) ) ;
338349
@@ -359,15 +370,16 @@ impl<T: Clone> Vec<T> {
359370 ///
360371 /// ```
361372 /// let mut vec = vec!["hello"];
362- /// vec.grow(2, &( "world") );
373+ /// vec.grow(2, "world");
363374 /// assert_eq!(vec, vec!["hello", "world", "world"]);
364375 /// ```
365- pub fn grow ( & mut self , n : uint , value : & T ) {
376+ #[ stable]
377+ pub fn grow ( & mut self , n : uint , value : T ) {
366378 self . reserve_additional ( n) ;
367379 let mut i: uint = 0 u;
368380
369381 while i < n {
370- self . push ( ( * value) . clone ( ) ) ;
382+ self . push ( value. clone ( ) ) ;
371383 i += 1 u;
372384 }
373385 }
@@ -382,15 +394,17 @@ impl<T: Clone> Vec<T> {
382394 /// # Example
383395 ///
384396 /// ```
397+ /// # #![allow(deprecated)]
385398 /// let mut vec = vec!["a", "b", "c"];
386399 /// vec.grow_set(1, &("fill"), "d");
387400 /// vec.grow_set(4, &("fill"), "e");
388401 /// assert_eq!(vec, vec!["a", "d", "c", "fill", "e"]);
389402 /// ```
403+ #[ deprecated = "call .grow() and .push() manually instead" ]
390404 pub fn grow_set ( & mut self , index : uint , initval : & T , value : T ) {
391405 let l = self . len ( ) ;
392406 if index >= l {
393- self . grow ( index - l + 1 u, initval) ;
407+ self . grow ( index - l + 1 u, initval. clone ( ) ) ;
394408 }
395409 * self . get_mut ( index) = value;
396410 }
@@ -409,6 +423,7 @@ impl<T: Clone> Vec<T> {
409423 /// assert_eq!(even, vec![2i, 4]);
410424 /// assert_eq!(odd, vec![1i, 3]);
411425 /// ```
426+ #[ experimental]
412427 pub fn partitioned ( & self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) {
413428 let mut lefts = Vec :: new ( ) ;
414429 let mut rights = Vec :: new ( ) ;
@@ -449,6 +464,7 @@ impl<T:Clone> Clone for Vec<T> {
449464 }
450465}
451466
467+ #[ experimental = "waiting on Index stability" ]
452468impl < T > Index < uint , T > for Vec < T > {
453469 #[ inline]
454470 #[ allow( deprecated) ] // allow use of get
@@ -506,6 +522,8 @@ impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
506522 self . as_mut_slice ( ) . slice_mut_ ( start, end)
507523 }
508524}
525+
526+ #[ experimental = "waiting on FromIterator stability" ]
509527impl < T > FromIterator < T > for Vec < T > {
510528 #[ inline]
511529 fn from_iter < I : Iterator < T > > ( mut iterator : I ) -> Vec < T > {
@@ -518,6 +536,7 @@ impl<T> FromIterator<T> for Vec<T> {
518536 }
519537}
520538
539+ #[ experimental = "waiting on Extendable stability" ]
521540impl < T > Extendable < T > for Vec < T > {
522541 #[ inline]
523542 fn extend < I : Iterator < T > > ( & mut self , mut iterator : I ) {
@@ -529,43 +548,52 @@ impl<T> Extendable<T> for Vec<T> {
529548 }
530549}
531550
551+ #[ unstable = "waiting on PartialEq stability" ]
532552impl < T : PartialEq > PartialEq for Vec < T > {
533553 #[ inline]
534554 fn eq ( & self , other : & Vec < T > ) -> bool {
535555 self . as_slice ( ) == other. as_slice ( )
536556 }
537557}
538558
559+ #[ unstable = "waiting on PartialOrd stability" ]
539560impl < T : PartialOrd > PartialOrd for Vec < T > {
540561 #[ inline]
541562 fn partial_cmp ( & self , other : & Vec < T > ) -> Option < Ordering > {
542563 self . as_slice ( ) . partial_cmp ( & other. as_slice ( ) )
543564 }
544565}
545566
567+ #[ unstable = "waiting on Eq stability" ]
546568impl < T : Eq > Eq for Vec < T > { }
547569
570+ #[ experimental]
548571impl < T : PartialEq , V : Slice < T > > Equiv < V > for Vec < T > {
549572 #[ inline]
550573 fn equiv ( & self , other : & V ) -> bool { self . as_slice ( ) == other. as_slice ( ) }
551574}
552575
576+ #[ unstable = "waiting on Ord stability" ]
553577impl < T : Ord > Ord for Vec < T > {
554578 #[ inline]
555579 fn cmp ( & self , other : & Vec < T > ) -> Ordering {
556580 self . as_slice ( ) . cmp ( & other. as_slice ( ) )
557581 }
558582}
559583
584+ #[ experimental = "waiting on Collection stability" ]
560585impl < T > Collection for Vec < T > {
561586 #[ inline]
587+ #[ stable]
562588 fn len ( & self ) -> uint {
563589 self . len
564590 }
565591}
566592
567593impl < T : Clone > CloneableVector < T > for Vec < T > {
594+ #[ deprecated = "call .clone() instead" ]
568595 fn to_vec ( & self ) -> Vec < T > { self . clone ( ) }
596+ #[ deprecated = "move the vector instead" ]
569597 fn into_vec ( self ) -> Vec < T > { self }
570598}
571599
@@ -600,6 +628,7 @@ impl<T> Vec<T> {
600628 /// assert_eq!(vec.capacity(), 10);
601629 /// ```
602630 #[ inline]
631+ #[ stable]
603632 pub fn capacity ( & self ) -> uint {
604633 self . cap
605634 }
@@ -683,6 +712,7 @@ impl<T> Vec<T> {
683712 /// let mut vec = vec![1i, 2, 3];
684713 /// vec.shrink_to_fit();
685714 /// ```
715+ #[ stable]
686716 pub fn shrink_to_fit ( & mut self ) {
687717 if mem:: size_of :: < T > ( ) == 0 { return }
688718
@@ -717,6 +747,7 @@ impl<T> Vec<T> {
717747 /// assert_eq!(vec, vec![1, 2, 3]);
718748 /// ```
719749 #[ inline]
750+ #[ deprecated = "call .push() instead" ]
720751 pub fn append_one ( mut self , x : T ) -> Vec < T > {
721752 self . push ( x) ;
722753 self
@@ -734,6 +765,7 @@ impl<T> Vec<T> {
734765 /// vec.truncate(2);
735766 /// assert_eq!(vec, vec![1, 2]);
736767 /// ```
768+ #[ stable]
737769 pub fn truncate ( & mut self , len : uint ) {
738770 unsafe {
739771 // drop any extra elements
@@ -757,6 +789,7 @@ impl<T> Vec<T> {
757789 /// foo(vec.as_mut_slice());
758790 /// ```
759791 #[ inline]
792+ #[ stable]
760793 pub fn as_mut_slice < ' a > ( & ' a mut self ) -> & ' a mut [ T ] {
761794 unsafe {
762795 mem:: transmute ( RawSlice {
@@ -796,7 +829,6 @@ impl<T> Vec<T> {
796829 }
797830 }
798831
799-
800832 /// Sets the length of a vector.
801833 ///
802834 /// This will explicitly set the size of the vector, without actually
@@ -812,6 +844,7 @@ impl<T> Vec<T> {
812844 /// }
813845 /// ```
814846 #[ inline]
847+ #[ stable]
815848 pub unsafe fn set_len ( & mut self , len : uint ) {
816849 self . len = len;
817850 }
@@ -850,6 +883,7 @@ impl<T> Vec<T> {
850883 /// assert_eq!(vec, vec![1i, 4, 3]);
851884 /// ```
852885 #[ inline]
886+ #[ unstable = "this is likely to be moved to actual indexing" ]
853887 pub fn get_mut < ' a > ( & ' a mut self , index : uint ) -> & ' a mut T {
854888 & mut self . as_mut_slice ( ) [ index]
855889 }
@@ -1020,6 +1054,7 @@ impl<T> Vec<T> {
10201054 /// assert_eq!(v.swap_remove(2), None);
10211055 /// ```
10221056 #[ inline]
1057+ #[ unstable = "the naming of this function may be altered" ]
10231058 pub fn swap_remove ( & mut self , index : uint ) -> Option < T > {
10241059 let length = self . len ( ) ;
10251060 if length > 0 && index < length - 1 {
@@ -1088,6 +1123,7 @@ impl<T> Vec<T> {
10881123 /// vec.insert(4, 5);
10891124 /// assert_eq!(vec, vec![1, 4, 2, 3, 5]);
10901125 /// ```
1126+ #[ stable]
10911127 pub fn insert ( & mut self , index : uint , element : T ) {
10921128 let len = self . len ( ) ;
10931129 assert ! ( index <= len) ;
@@ -1124,6 +1160,7 @@ impl<T> Vec<T> {
11241160 /// // v is unchanged:
11251161 /// assert_eq!(v, vec![1, 3]);
11261162 /// ```
1163+ #[ stable]
11271164 pub fn remove ( & mut self , index : uint ) -> Option < T > {
11281165 let len = self . len ( ) ;
11291166 if index < len {
@@ -1410,6 +1447,7 @@ impl<T> Vec<T> {
14101447 /// vec.retain(|x| x%2 == 0);
14111448 /// assert_eq!(vec, vec![2, 4]);
14121449 /// ```
1450+ #[ unstable = "the closure argument may become an unboxed closure" ]
14131451 pub fn retain ( & mut self , f: |& T | -> bool) {
14141452 let len = self . len ( ) ;
14151453 let mut del = 0 u;
@@ -1441,6 +1479,7 @@ impl<T> Vec<T> {
14411479 /// vec.grow_fn(3, |i| i);
14421480 /// assert_eq!(vec, vec![0, 1, 0, 1, 2]);
14431481 /// ```
1482+ #[ unstable = "this function may be renamed or change to unboxed closures" ]
14441483 pub fn grow_fn ( & mut self , n : uint , f: |uint| -> T ) {
14451484 self . reserve_additional ( n) ;
14461485 for i in range ( 0 u, n) {
@@ -1467,8 +1506,10 @@ impl<T:Ord> Vec<T> {
14671506 }
14681507}
14691508
1509+ #[ experimental = "waiting on Mutable stability" ]
14701510impl < T > Mutable for Vec < T > {
14711511 #[ inline]
1512+ #[ stable]
14721513 fn clear ( & mut self ) {
14731514 self . truncate ( 0 )
14741515 }
@@ -1499,6 +1540,7 @@ impl<T: PartialEq> Vec<T> {
14991540 /// vec.dedup();
15001541 /// assert_eq!(vec, vec![1i, 2, 3, 2]);
15011542 /// ```
1543+ #[ unstable = "this function may be renamed" ]
15021544 pub fn dedup ( & mut self ) {
15031545 unsafe {
15041546 // Although we have a mutable reference to `self`, we cannot make
@@ -1596,6 +1638,7 @@ impl<T> Slice<T> for Vec<T> {
15961638 /// foo(vec.as_slice());
15971639 /// ```
15981640 #[ inline]
1641+ #[ stable]
15991642 fn as_slice < ' a > ( & ' a self ) -> & ' a [ T ] {
16001643 unsafe { mem:: transmute ( RawSlice { data : self . as_ptr ( ) , len : self . len } ) }
16011644 }
@@ -1627,18 +1670,21 @@ impl<T> Drop for Vec<T> {
16271670 }
16281671}
16291672
1673+ #[ stable]
16301674impl < T > Default for Vec < T > {
16311675 fn default ( ) -> Vec < T > {
16321676 Vec :: new ( )
16331677 }
16341678}
16351679
1680+ #[ experimental = "waiting on Show stability" ]
16361681impl < T : fmt:: Show > fmt:: Show for Vec < T > {
16371682 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
16381683 self . as_slice ( ) . fmt ( f)
16391684 }
16401685}
16411686
1687+ #[ experimental = "waiting on MutableSeq stability" ]
16421688impl < T > MutableSeq < T > for Vec < T > {
16431689 /// Appends an element to the back of a collection.
16441690 ///
@@ -1654,6 +1700,7 @@ impl<T> MutableSeq<T> for Vec<T> {
16541700 /// assert_eq!(vec, vec!(1, 2, 3));
16551701 /// ```
16561702 #[ inline]
1703+ #[ stable]
16571704 fn push ( & mut self , value : T ) {
16581705 if mem:: size_of :: < T > ( ) == 0 {
16591706 // zero-size types consume no memory, so we can't rely on the address space running out
@@ -1680,6 +1727,7 @@ impl<T> MutableSeq<T> for Vec<T> {
16801727 }
16811728
16821729 #[ inline]
1730+ #[ stable]
16831731 fn pop ( & mut self ) -> Option < T > {
16841732 if self . len == 0 {
16851733 None
@@ -1765,6 +1813,7 @@ impl<T> Drop for MoveItems<T> {
17651813/// vector contains the first element of the i-th tuple of the input iterator,
17661814/// and the i-th element of the second vector contains the second element
17671815/// of the i-th tuple of the input iterator.
1816+ #[ unstable = "this functionality may become more generic over time" ]
17681817pub fn unzip < T , U , V : Iterator < ( T , U ) > > ( mut iter : V ) -> ( Vec < T > , Vec < U > ) {
17691818 let ( lo, _) = iter. size_hint ( ) ;
17701819 let mut ts = Vec :: with_capacity ( lo) ;
@@ -1777,6 +1826,7 @@ pub fn unzip<T, U, V: Iterator<(T, U)>>(mut iter: V) -> (Vec<T>, Vec<U>) {
17771826}
17781827
17791828/// Unsafe vector operations.
1829+ #[ unstable]
17801830pub mod raw {
17811831 use super :: Vec ;
17821832 use core:: ptr;
@@ -1786,6 +1836,7 @@ pub mod raw {
17861836 /// The elements of the buffer are copied into the vector without cloning,
17871837 /// as if `ptr::read()` were called on them.
17881838 #[ inline]
1839+ #[ unstable]
17891840 pub unsafe fn from_buf < T > ( ptr : * const T , elts : uint ) -> Vec < T > {
17901841 let mut dst = Vec :: with_capacity ( elts) ;
17911842 dst. set_len ( elts) ;
0 commit comments