File tree 1 file changed +28
-0
lines changed
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -363,6 +363,21 @@ impl<T:Clone> Clone for Vec<T> {
363
363
}
364
364
}
365
365
366
+ impl < T > Index < uint , T > for Vec < T > {
367
+ #[ inline]
368
+ fn index < ' a > ( & ' a self , index : & uint ) -> & ' a T {
369
+ self . get ( * index)
370
+ }
371
+ }
372
+
373
+ // FIXME(#12825) Indexing will always try IndexMut first and that causes issues.
374
+ /*impl<T> IndexMut<uint,T> for Vec<T> {
375
+ #[inline]
376
+ fn index_mut<'a>(&'a mut self, index: &uint) -> &'a mut T {
377
+ self.get_mut(*index)
378
+ }
379
+ }*/
380
+
366
381
impl < T > FromIterator < T > for Vec < T > {
367
382
#[ inline]
368
383
fn from_iter < I : Iterator < T > > ( mut iterator : I ) -> Vec < T > {
@@ -1847,6 +1862,19 @@ mod tests {
1847
1862
v. truncate ( 0 ) ;
1848
1863
}
1849
1864
1865
+ #[ test]
1866
+ fn test_index ( ) {
1867
+ let vec = vec ! ( 1 i, 2 , 3 ) ;
1868
+ assert ! ( vec[ 1 ] == 2 ) ;
1869
+ }
1870
+
1871
+ #[ test]
1872
+ #[ should_fail]
1873
+ fn test_index_out_of_bounds ( ) {
1874
+ let vec = vec ! ( 1 i, 2 , 3 ) ;
1875
+ let _ = vec[ 3 ] ;
1876
+ }
1877
+
1850
1878
#[ bench]
1851
1879
fn bench_new ( b : & mut Bencher ) {
1852
1880
b. iter ( || {
You can’t perform that action at this time.
0 commit comments