File tree 2 files changed +18
-3
lines changed
2 files changed +18
-3
lines changed Original file line number Diff line number Diff line change @@ -638,7 +638,7 @@ shr_impl!(uint u8 u16 u32 u64 int i8 i16 i32 i64)
638
638
* ```
639
639
*/
640
640
#[ lang="index" ]
641
- pub trait Index < Index , Sized ? Result > {
641
+ pub trait Index < Index , Sized ? Result > for Sized ? {
642
642
/// The method for the indexing (`Foo[Bar]`) operation
643
643
fn index < ' a > ( & ' a self , index : & Index ) -> & ' a Result ;
644
644
}
@@ -669,7 +669,7 @@ pub trait Index<Index, Sized? Result> {
669
669
* ```
670
670
*/
671
671
#[ lang="index_mut" ]
672
- pub trait IndexMut < Index , Result > {
672
+ pub trait IndexMut < Index , Result > for Sized ? {
673
673
/// The method for the indexing (`Foo[Bar]`) operation
674
674
fn index_mut < ' a > ( & ' a mut self , index : & Index ) -> & ' a mut Result ;
675
675
}
Original file line number Diff line number Diff line change @@ -256,7 +256,6 @@ pub trait SlicePrelude<T> for Sized? {
256
256
#[ inline]
257
257
#[ experimental = "not triaged yet" ]
258
258
fn is_empty ( & self ) -> bool { self . len ( ) == 0 }
259
-
260
259
/// Returns a mutable reference to the element at the given index,
261
260
/// or `None` if the index is out of bounds
262
261
#[ unstable = "waiting on final error conventions" ]
@@ -698,6 +697,22 @@ impl<T> SlicePrelude<T> for [T] {
698
697
}
699
698
}
700
699
700
+ impl < T > ops:: Index < uint , T > for [ T ] {
701
+ fn index ( & self , & index: & uint ) -> & T {
702
+ assert ! ( index < self . len( ) ) ;
703
+
704
+ unsafe { mem:: transmute ( self . repr ( ) . data . offset ( index as int ) ) }
705
+ }
706
+ }
707
+
708
+ impl < T > ops:: IndexMut < uint , T > for [ T ] {
709
+ fn index_mut ( & mut self , & index: & uint ) -> & mut T {
710
+ assert ! ( index < self . len( ) ) ;
711
+
712
+ unsafe { mem:: transmute ( self . repr ( ) . data . offset ( index as int ) ) }
713
+ }
714
+ }
715
+
701
716
impl < T > ops:: Slice < uint , [ T ] > for [ T ] {
702
717
#[ inline]
703
718
fn as_slice_ < ' a > ( & ' a self ) -> & ' a [ T ] {
You can’t perform that action at this time.
0 commit comments