@@ -560,7 +560,7 @@ impl<T> ops::Index<ops::RangeTo<usize>> for [T] {
560
560
561
561
#[ inline]
562
562
fn index ( & self , index : ops:: RangeTo < usize > ) -> & [ T ] {
563
- self . index ( ops :: Range { start : 0 , end : index. end } )
563
+ self . index ( 0 .. index. end )
564
564
}
565
565
}
566
566
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -569,7 +569,7 @@ impl<T> ops::Index<ops::RangeFrom<usize>> for [T] {
569
569
570
570
#[ inline]
571
571
fn index ( & self , index : ops:: RangeFrom < usize > ) -> & [ T ] {
572
- self . index ( ops :: Range { start : index. start , end : self . len ( ) } )
572
+ self . index ( index. start .. self . len ( ) )
573
573
}
574
574
}
575
575
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -582,6 +582,32 @@ impl<T> ops::Index<RangeFull> for [T] {
582
582
}
583
583
}
584
584
585
+ #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
586
+ impl < T > ops:: Index < ops:: RangeInclusive < usize > > for [ T ] {
587
+ type Output = [ T ] ;
588
+
589
+ #[ inline]
590
+ fn index ( & self , index : ops:: RangeInclusive < usize > ) -> & [ T ] {
591
+ match index {
592
+ ops:: RangeInclusive :: Empty { .. } => & [ ] ,
593
+ ops:: RangeInclusive :: NonEmpty { end, .. } if end == usize:: max_value ( ) =>
594
+ panic ! ( "attempted to index slice up to maximum usize" ) ,
595
+ ops:: RangeInclusive :: NonEmpty { start, end } =>
596
+ self . index ( start .. end+1 )
597
+ }
598
+ }
599
+ }
600
+ #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
601
+ impl < T > ops:: Index < ops:: RangeToInclusive < usize > > for [ T ] {
602
+ type Output = [ T ] ;
603
+
604
+ #[ inline]
605
+ fn index ( & self , index : ops:: RangeToInclusive < usize > ) -> & [ T ] {
606
+ // SNAP 3391630 change this to `0...index.end`
607
+ self . index ( ops:: RangeInclusive :: NonEmpty { start : 0 , end : index. end } )
608
+ }
609
+ }
610
+
585
611
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
586
612
impl < T > ops:: IndexMut < ops:: Range < usize > > for [ T ] {
587
613
#[ inline]
@@ -603,15 +629,15 @@ impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
603
629
impl < T > ops:: IndexMut < ops:: RangeTo < usize > > for [ T ] {
604
630
#[ inline]
605
631
fn index_mut ( & mut self , index : ops:: RangeTo < usize > ) -> & mut [ T ] {
606
- self . index_mut ( ops :: Range { start : 0 , end : index. end } )
632
+ self . index_mut ( 0 .. index. end )
607
633
}
608
634
}
609
635
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
610
636
impl < T > ops:: IndexMut < ops:: RangeFrom < usize > > for [ T ] {
611
637
#[ inline]
612
638
fn index_mut ( & mut self , index : ops:: RangeFrom < usize > ) -> & mut [ T ] {
613
639
let len = self . len ( ) ;
614
- self . index_mut ( ops :: Range { start : index. start , end : len } )
640
+ self . index_mut ( index. start .. len)
615
641
}
616
642
}
617
643
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
@@ -622,6 +648,27 @@ impl<T> ops::IndexMut<RangeFull> for [T] {
622
648
}
623
649
}
624
650
651
+ #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
652
+ impl < T > ops:: IndexMut < ops:: RangeInclusive < usize > > for [ T ] {
653
+ #[ inline]
654
+ fn index_mut ( & mut self , index : ops:: RangeInclusive < usize > ) -> & mut [ T ] {
655
+ match index {
656
+ ops:: RangeInclusive :: Empty { .. } => & mut [ ] ,
657
+ ops:: RangeInclusive :: NonEmpty { end, .. } if end == usize:: max_value ( ) =>
658
+ panic ! ( "attempted to index slice up to maximum usize" ) ,
659
+ ops:: RangeInclusive :: NonEmpty { start, end } =>
660
+ self . index_mut ( start .. end+1 )
661
+ }
662
+ }
663
+ }
664
+ #[ unstable( feature = "inclusive_range" , reason = "recently added, follows RFC" , issue = "28237" ) ]
665
+ impl < T > ops:: IndexMut < ops:: RangeToInclusive < usize > > for [ T ] {
666
+ #[ inline]
667
+ fn index_mut ( & mut self , index : ops:: RangeToInclusive < usize > ) -> & mut [ T ] {
668
+ // SNAP 3391630 change this to `0...index.end`
669
+ self . index_mut ( ops:: RangeInclusive :: NonEmpty { start : 0 , end : index. end } )
670
+ }
671
+ }
625
672
626
673
////////////////////////////////////////////////////////////////////////////////
627
674
// Common traits
0 commit comments