File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 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> {
363363 }
364364}
365365
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+
366381impl < T > FromIterator < T > for Vec < T > {
367382 #[ inline]
368383 fn from_iter < I : Iterator < T > > ( mut iterator : I ) -> Vec < T > {
@@ -1847,6 +1862,19 @@ mod tests {
18471862 v. truncate ( 0 ) ;
18481863 }
18491864
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+
18501878 #[ bench]
18511879 fn bench_new ( b : & mut Bencher ) {
18521880 b. iter ( || {
You can’t perform that action at this time.
0 commit comments