@@ -99,6 +99,7 @@ use slice::{Items, MutItems};
99
99
/// to use `Vec::with_capacity` whenever possible to specify how big the vector
100
100
/// is expected to get.
101
101
#[ unsafe_no_drop_flag]
102
+ #[ stable]
102
103
pub struct Vec < T > {
103
104
len : uint ,
104
105
cap : uint ,
@@ -116,6 +117,7 @@ impl<T> Vec<T> {
116
117
/// let mut vec: Vec<int> = Vec::new();
117
118
/// ```
118
119
#[ inline]
120
+ #[ stable]
119
121
pub fn new ( ) -> Vec < T > {
120
122
// We want ptr to never be NULL so instead we set it to some arbitrary
121
123
// non-null value which is fine since we never call deallocate on the ptr
@@ -152,6 +154,7 @@ impl<T> Vec<T> {
152
154
/// vec.push(11);
153
155
/// ```
154
156
#[ inline]
157
+ #[ stable]
155
158
pub fn with_capacity ( capacity : uint ) -> Vec < T > {
156
159
if mem:: size_of :: < T > ( ) == 0 {
157
160
Vec { len : 0 , cap : uint:: MAX , ptr : EMPTY as * mut T }
@@ -177,6 +180,8 @@ impl<T> Vec<T> {
177
180
/// assert_eq!(vec, vec![0, 2, 4]);
178
181
/// ```
179
182
#[ inline]
183
+ #[ unstable = "the naming is uncertain as well as this migrating to unboxed \
184
+ closures in the future"]
180
185
pub fn from_fn ( length : uint , op: |uint| -> T ) -> Vec < T > {
181
186
unsafe {
182
187
let mut xs = Vec :: with_capacity ( length) ;
@@ -229,6 +234,7 @@ impl<T> Vec<T> {
229
234
/// }
230
235
/// }
231
236
/// ```
237
+ #[ experimental]
232
238
pub unsafe fn from_raw_parts ( length : uint , capacity : uint ,
233
239
ptr : * mut T ) -> Vec < T > {
234
240
Vec { len : length, cap : capacity, ptr : ptr }
@@ -249,6 +255,7 @@ impl<T> Vec<T> {
249
255
/// assert_eq!(odd, vec![1, 3]);
250
256
/// ```
251
257
#[ inline]
258
+ #[ experimental]
252
259
pub fn partition ( self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) {
253
260
let mut lefts = Vec :: new ( ) ;
254
261
let mut rights = Vec :: new ( ) ;
@@ -277,6 +284,7 @@ impl<T: Clone> Vec<T> {
277
284
/// assert_eq!(vec, vec![1, 2, 3, 4]);
278
285
/// ```
279
286
#[ inline]
287
+ #[ deprecated = "this function has been deprecated in favor of extend()" ]
280
288
pub fn append ( mut self , second : & [ T ] ) -> Vec < T > {
281
289
self . push_all ( second) ;
282
290
self
@@ -291,6 +299,7 @@ impl<T: Clone> Vec<T> {
291
299
/// let vec = Vec::from_slice(slice);
292
300
/// ```
293
301
#[ inline]
302
+ #[ deprecated = "this function has been deprecated in favor of to_vec()" ]
294
303
pub fn from_slice ( values : & [ T ] ) -> Vec < T > {
295
304
let mut vector = Vec :: new ( ) ;
296
305
vector. push_all ( values) ;
@@ -307,6 +316,7 @@ impl<T: Clone> Vec<T> {
307
316
/// println!("{}", vec); // prints [hi, hi, hi]
308
317
/// ```
309
318
#[ inline]
319
+ #[ unstable = "this functionality may become more generic over all collections" ]
310
320
pub fn from_elem ( length : uint , value : T ) -> Vec < T > {
311
321
unsafe {
312
322
let mut xs = Vec :: with_capacity ( length) ;
@@ -333,6 +343,7 @@ impl<T: Clone> Vec<T> {
333
343
/// assert_eq!(vec, vec![1, 2, 3, 4]);
334
344
/// ```
335
345
#[ inline]
346
+ #[ experimental]
336
347
pub fn push_all ( & mut self , other : & [ T ] ) {
337
348
self . reserve_additional ( other. len ( ) ) ;
338
349
@@ -359,15 +370,16 @@ impl<T: Clone> Vec<T> {
359
370
///
360
371
/// ```
361
372
/// let mut vec = vec!["hello"];
362
- /// vec.grow(2, &( "world") );
373
+ /// vec.grow(2, "world");
363
374
/// assert_eq!(vec, vec!["hello", "world", "world"]);
364
375
/// ```
365
- pub fn grow ( & mut self , n : uint , value : & T ) {
376
+ #[ stable]
377
+ pub fn grow ( & mut self , n : uint , value : T ) {
366
378
self . reserve_additional ( n) ;
367
379
let mut i: uint = 0 u;
368
380
369
381
while i < n {
370
- self . push ( ( * value) . clone ( ) ) ;
382
+ self . push ( value. clone ( ) ) ;
371
383
i += 1 u;
372
384
}
373
385
}
@@ -382,15 +394,17 @@ impl<T: Clone> Vec<T> {
382
394
/// # Example
383
395
///
384
396
/// ```
397
+ /// # #![allow(deprecated)]
385
398
/// let mut vec = vec!["a", "b", "c"];
386
399
/// vec.grow_set(1, &("fill"), "d");
387
400
/// vec.grow_set(4, &("fill"), "e");
388
401
/// assert_eq!(vec, vec!["a", "d", "c", "fill", "e"]);
389
402
/// ```
403
+ #[ deprecated = "call .grow() and .push() manually instead" ]
390
404
pub fn grow_set ( & mut self , index : uint , initval : & T , value : T ) {
391
405
let l = self . len ( ) ;
392
406
if index >= l {
393
- self . grow ( index - l + 1 u, initval) ;
407
+ self . grow ( index - l + 1 u, initval. clone ( ) ) ;
394
408
}
395
409
* self . get_mut ( index) = value;
396
410
}
@@ -409,6 +423,7 @@ impl<T: Clone> Vec<T> {
409
423
/// assert_eq!(even, vec![2i, 4]);
410
424
/// assert_eq!(odd, vec![1i, 3]);
411
425
/// ```
426
+ #[ experimental]
412
427
pub fn partitioned ( & self , f: |& T | -> bool) -> ( Vec < T > , Vec < T > ) {
413
428
let mut lefts = Vec :: new ( ) ;
414
429
let mut rights = Vec :: new ( ) ;
@@ -449,6 +464,7 @@ impl<T:Clone> Clone for Vec<T> {
449
464
}
450
465
}
451
466
467
+ #[ experimental = "waiting on Index stability" ]
452
468
impl < T > Index < uint , T > for Vec < T > {
453
469
#[ inline]
454
470
#[ allow( deprecated) ] // allow use of get
@@ -506,6 +522,8 @@ impl<T> ops::SliceMut<uint, [T]> for Vec<T> {
506
522
self . as_mut_slice ( ) . slice_mut_ ( start, end)
507
523
}
508
524
}
525
+
526
+ #[ experimental = "waiting on FromIterator stability" ]
509
527
impl < T > FromIterator < T > for Vec < T > {
510
528
#[ inline]
511
529
fn from_iter < I : Iterator < T > > ( mut iterator : I ) -> Vec < T > {
@@ -518,6 +536,7 @@ impl<T> FromIterator<T> for Vec<T> {
518
536
}
519
537
}
520
538
539
+ #[ experimental = "waiting on Extendable stability" ]
521
540
impl < T > Extendable < T > for Vec < T > {
522
541
#[ inline]
523
542
fn extend < I : Iterator < T > > ( & mut self , mut iterator : I ) {
@@ -529,43 +548,52 @@ impl<T> Extendable<T> for Vec<T> {
529
548
}
530
549
}
531
550
551
+ #[ unstable = "waiting on PartialEq stability" ]
532
552
impl < T : PartialEq > PartialEq for Vec < T > {
533
553
#[ inline]
534
554
fn eq ( & self , other : & Vec < T > ) -> bool {
535
555
self . as_slice ( ) == other. as_slice ( )
536
556
}
537
557
}
538
558
559
+ #[ unstable = "waiting on PartialOrd stability" ]
539
560
impl < T : PartialOrd > PartialOrd for Vec < T > {
540
561
#[ inline]
541
562
fn partial_cmp ( & self , other : & Vec < T > ) -> Option < Ordering > {
542
563
self . as_slice ( ) . partial_cmp ( & other. as_slice ( ) )
543
564
}
544
565
}
545
566
567
+ #[ unstable = "waiting on Eq stability" ]
546
568
impl < T : Eq > Eq for Vec < T > { }
547
569
570
+ #[ experimental]
548
571
impl < T : PartialEq , V : Slice < T > > Equiv < V > for Vec < T > {
549
572
#[ inline]
550
573
fn equiv ( & self , other : & V ) -> bool { self . as_slice ( ) == other. as_slice ( ) }
551
574
}
552
575
576
+ #[ unstable = "waiting on Ord stability" ]
553
577
impl < T : Ord > Ord for Vec < T > {
554
578
#[ inline]
555
579
fn cmp ( & self , other : & Vec < T > ) -> Ordering {
556
580
self . as_slice ( ) . cmp ( & other. as_slice ( ) )
557
581
}
558
582
}
559
583
584
+ #[ experimental = "waiting on Collection stability" ]
560
585
impl < T > Collection for Vec < T > {
561
586
#[ inline]
587
+ #[ stable]
562
588
fn len ( & self ) -> uint {
563
589
self . len
564
590
}
565
591
}
566
592
567
593
impl < T : Clone > CloneableVector < T > for Vec < T > {
594
+ #[ deprecated = "call .clone() instead" ]
568
595
fn to_vec ( & self ) -> Vec < T > { self . clone ( ) }
596
+ #[ deprecated = "move the vector instead" ]
569
597
fn into_vec ( self ) -> Vec < T > { self }
570
598
}
571
599
@@ -600,6 +628,7 @@ impl<T> Vec<T> {
600
628
/// assert_eq!(vec.capacity(), 10);
601
629
/// ```
602
630
#[ inline]
631
+ #[ stable]
603
632
pub fn capacity ( & self ) -> uint {
604
633
self . cap
605
634
}
@@ -683,6 +712,7 @@ impl<T> Vec<T> {
683
712
/// let mut vec = vec![1i, 2, 3];
684
713
/// vec.shrink_to_fit();
685
714
/// ```
715
+ #[ stable]
686
716
pub fn shrink_to_fit ( & mut self ) {
687
717
if mem:: size_of :: < T > ( ) == 0 { return }
688
718
@@ -717,6 +747,7 @@ impl<T> Vec<T> {
717
747
/// assert_eq!(vec, vec![1, 2, 3]);
718
748
/// ```
719
749
#[ inline]
750
+ #[ deprecated = "call .push() instead" ]
720
751
pub fn append_one ( mut self , x : T ) -> Vec < T > {
721
752
self . push ( x) ;
722
753
self
@@ -734,6 +765,7 @@ impl<T> Vec<T> {
734
765
/// vec.truncate(2);
735
766
/// assert_eq!(vec, vec![1, 2]);
736
767
/// ```
768
+ #[ stable]
737
769
pub fn truncate ( & mut self , len : uint ) {
738
770
unsafe {
739
771
// drop any extra elements
@@ -757,6 +789,7 @@ impl<T> Vec<T> {
757
789
/// foo(vec.as_mut_slice());
758
790
/// ```
759
791
#[ inline]
792
+ #[ stable]
760
793
pub fn as_mut_slice < ' a > ( & ' a mut self ) -> & ' a mut [ T ] {
761
794
unsafe {
762
795
mem:: transmute ( RawSlice {
@@ -796,7 +829,6 @@ impl<T> Vec<T> {
796
829
}
797
830
}
798
831
799
-
800
832
/// Sets the length of a vector.
801
833
///
802
834
/// This will explicitly set the size of the vector, without actually
@@ -812,6 +844,7 @@ impl<T> Vec<T> {
812
844
/// }
813
845
/// ```
814
846
#[ inline]
847
+ #[ stable]
815
848
pub unsafe fn set_len ( & mut self , len : uint ) {
816
849
self . len = len;
817
850
}
@@ -850,6 +883,7 @@ impl<T> Vec<T> {
850
883
/// assert_eq!(vec, vec![1i, 4, 3]);
851
884
/// ```
852
885
#[ inline]
886
+ #[ unstable = "this is likely to be moved to actual indexing" ]
853
887
pub fn get_mut < ' a > ( & ' a mut self , index : uint ) -> & ' a mut T {
854
888
& mut self . as_mut_slice ( ) [ index]
855
889
}
@@ -1020,6 +1054,7 @@ impl<T> Vec<T> {
1020
1054
/// assert_eq!(v.swap_remove(2), None);
1021
1055
/// ```
1022
1056
#[ inline]
1057
+ #[ unstable = "the naming of this function may be altered" ]
1023
1058
pub fn swap_remove ( & mut self , index : uint ) -> Option < T > {
1024
1059
let length = self . len ( ) ;
1025
1060
if length > 0 && index < length - 1 {
@@ -1088,6 +1123,7 @@ impl<T> Vec<T> {
1088
1123
/// vec.insert(4, 5);
1089
1124
/// assert_eq!(vec, vec![1, 4, 2, 3, 5]);
1090
1125
/// ```
1126
+ #[ stable]
1091
1127
pub fn insert ( & mut self , index : uint , element : T ) {
1092
1128
let len = self . len ( ) ;
1093
1129
assert ! ( index <= len) ;
@@ -1124,6 +1160,7 @@ impl<T> Vec<T> {
1124
1160
/// // v is unchanged:
1125
1161
/// assert_eq!(v, vec![1, 3]);
1126
1162
/// ```
1163
+ #[ stable]
1127
1164
pub fn remove ( & mut self , index : uint ) -> Option < T > {
1128
1165
let len = self . len ( ) ;
1129
1166
if index < len {
@@ -1410,6 +1447,7 @@ impl<T> Vec<T> {
1410
1447
/// vec.retain(|x| x%2 == 0);
1411
1448
/// assert_eq!(vec, vec![2, 4]);
1412
1449
/// ```
1450
+ #[ unstable = "the closure argument may become an unboxed closure" ]
1413
1451
pub fn retain ( & mut self , f: |& T | -> bool) {
1414
1452
let len = self . len ( ) ;
1415
1453
let mut del = 0 u;
@@ -1441,6 +1479,7 @@ impl<T> Vec<T> {
1441
1479
/// vec.grow_fn(3, |i| i);
1442
1480
/// assert_eq!(vec, vec![0, 1, 0, 1, 2]);
1443
1481
/// ```
1482
+ #[ unstable = "this function may be renamed or change to unboxed closures" ]
1444
1483
pub fn grow_fn ( & mut self , n : uint , f: |uint| -> T ) {
1445
1484
self . reserve_additional ( n) ;
1446
1485
for i in range ( 0 u, n) {
@@ -1467,8 +1506,10 @@ impl<T:Ord> Vec<T> {
1467
1506
}
1468
1507
}
1469
1508
1509
+ #[ experimental = "waiting on Mutable stability" ]
1470
1510
impl < T > Mutable for Vec < T > {
1471
1511
#[ inline]
1512
+ #[ stable]
1472
1513
fn clear ( & mut self ) {
1473
1514
self . truncate ( 0 )
1474
1515
}
@@ -1499,6 +1540,7 @@ impl<T: PartialEq> Vec<T> {
1499
1540
/// vec.dedup();
1500
1541
/// assert_eq!(vec, vec![1i, 2, 3, 2]);
1501
1542
/// ```
1543
+ #[ unstable = "this function may be renamed" ]
1502
1544
pub fn dedup ( & mut self ) {
1503
1545
unsafe {
1504
1546
// Although we have a mutable reference to `self`, we cannot make
@@ -1596,6 +1638,7 @@ impl<T> Slice<T> for Vec<T> {
1596
1638
/// foo(vec.as_slice());
1597
1639
/// ```
1598
1640
#[ inline]
1641
+ #[ stable]
1599
1642
fn as_slice < ' a > ( & ' a self ) -> & ' a [ T ] {
1600
1643
unsafe { mem:: transmute ( RawSlice { data : self . as_ptr ( ) , len : self . len } ) }
1601
1644
}
@@ -1627,18 +1670,21 @@ impl<T> Drop for Vec<T> {
1627
1670
}
1628
1671
}
1629
1672
1673
+ #[ stable]
1630
1674
impl < T > Default for Vec < T > {
1631
1675
fn default ( ) -> Vec < T > {
1632
1676
Vec :: new ( )
1633
1677
}
1634
1678
}
1635
1679
1680
+ #[ experimental = "waiting on Show stability" ]
1636
1681
impl < T : fmt:: Show > fmt:: Show for Vec < T > {
1637
1682
fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
1638
1683
self . as_slice ( ) . fmt ( f)
1639
1684
}
1640
1685
}
1641
1686
1687
+ #[ experimental = "waiting on MutableSeq stability" ]
1642
1688
impl < T > MutableSeq < T > for Vec < T > {
1643
1689
/// Appends an element to the back of a collection.
1644
1690
///
@@ -1654,6 +1700,7 @@ impl<T> MutableSeq<T> for Vec<T> {
1654
1700
/// assert_eq!(vec, vec!(1, 2, 3));
1655
1701
/// ```
1656
1702
#[ inline]
1703
+ #[ stable]
1657
1704
fn push ( & mut self , value : T ) {
1658
1705
if mem:: size_of :: < T > ( ) == 0 {
1659
1706
// 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> {
1680
1727
}
1681
1728
1682
1729
#[ inline]
1730
+ #[ stable]
1683
1731
fn pop ( & mut self ) -> Option < T > {
1684
1732
if self . len == 0 {
1685
1733
None
@@ -1765,6 +1813,7 @@ impl<T> Drop for MoveItems<T> {
1765
1813
/// vector contains the first element of the i-th tuple of the input iterator,
1766
1814
/// and the i-th element of the second vector contains the second element
1767
1815
/// of the i-th tuple of the input iterator.
1816
+ #[ unstable = "this functionality may become more generic over time" ]
1768
1817
pub fn unzip < T , U , V : Iterator < ( T , U ) > > ( mut iter : V ) -> ( Vec < T > , Vec < U > ) {
1769
1818
let ( lo, _) = iter. size_hint ( ) ;
1770
1819
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>) {
1777
1826
}
1778
1827
1779
1828
/// Unsafe vector operations.
1829
+ #[ unstable]
1780
1830
pub mod raw {
1781
1831
use super :: Vec ;
1782
1832
use core:: ptr;
@@ -1786,6 +1836,7 @@ pub mod raw {
1786
1836
/// The elements of the buffer are copied into the vector without cloning,
1787
1837
/// as if `ptr::read()` were called on them.
1788
1838
#[ inline]
1839
+ #[ unstable]
1789
1840
pub unsafe fn from_buf < T > ( ptr : * const T , elts : uint ) -> Vec < T > {
1790
1841
let mut dst = Vec :: with_capacity ( elts) ;
1791
1842
dst. set_len ( elts) ;
0 commit comments