@@ -535,6 +535,16 @@ fn slice_index_order_fail(index: usize, end: usize) -> ! {
535
535
536
536
// FIXME implement indexing with inclusive ranges
537
537
538
+ /// Implements slicing with syntax `&self[begin .. end]`.
539
+ ///
540
+ /// Returns a slice of self for the index range [`begin`..`end`).
541
+ ///
542
+ /// This operation is `O(1)`.
543
+ ///
544
+ /// # Panics
545
+ ///
546
+ /// Requires that `begin <= end` and `end <= self.len()`,
547
+ /// otherwise slicing will panic.
538
548
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
539
549
impl < T > ops:: Index < ops:: Range < usize > > for [ T ] {
540
550
type Output = [ T ] ;
@@ -554,6 +564,13 @@ impl<T> ops::Index<ops::Range<usize>> for [T] {
554
564
}
555
565
}
556
566
}
567
+
568
+ /// Implements slicing with syntax `&self[.. end]`.
569
+ ///
570
+ /// Returns a slice of self from the beginning until but not including
571
+ /// the index `end`.
572
+ ///
573
+ /// Equivalent to `&self[0 .. end]`
557
574
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
558
575
impl < T > ops:: Index < ops:: RangeTo < usize > > for [ T ] {
559
576
type Output = [ T ] ;
@@ -563,6 +580,12 @@ impl<T> ops::Index<ops::RangeTo<usize>> for [T] {
563
580
self . index ( 0 .. index. end )
564
581
}
565
582
}
583
+
584
+ /// Implements slicing with syntax `&self[begin ..]`.
585
+ ///
586
+ /// Returns a slice of self from and including the index `begin` until the end.
587
+ ///
588
+ /// Equivalent to `&self[begin .. self.len()]`
566
589
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
567
590
impl < T > ops:: Index < ops:: RangeFrom < usize > > for [ T ] {
568
591
type Output = [ T ] ;
@@ -572,6 +595,12 @@ impl<T> ops::Index<ops::RangeFrom<usize>> for [T] {
572
595
self . index ( index. start .. self . len ( ) )
573
596
}
574
597
}
598
+
599
+ /// Implements slicing with syntax `&self[..]`.
600
+ ///
601
+ /// Returns a slice of the whole slice. This operation can not panic.
602
+ ///
603
+ /// Equivalent to `&self[0 .. self.len()]`
575
604
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
576
605
impl < T > ops:: Index < RangeFull > for [ T ] {
577
606
type Output = [ T ] ;
@@ -608,6 +637,16 @@ impl<T> ops::Index<ops::RangeToInclusive<usize>> for [T] {
608
637
}
609
638
}
610
639
640
+ /// Implements mutable slicing with syntax `&mut self[begin .. end]`.
641
+ ///
642
+ /// Returns a slice of self for the index range [`begin`..`end`).
643
+ ///
644
+ /// This operation is `O(1)`.
645
+ ///
646
+ /// # Panics
647
+ ///
648
+ /// Requires that `begin <= end` and `end <= self.len()`,
649
+ /// otherwise slicing will panic.
611
650
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
612
651
impl < T > ops:: IndexMut < ops:: Range < usize > > for [ T ] {
613
652
#[ inline]
@@ -625,13 +664,26 @@ impl<T> ops::IndexMut<ops::Range<usize>> for [T] {
625
664
}
626
665
}
627
666
}
667
+
668
+ /// Implements mutable slicing with syntax `&mut self[.. end]`.
669
+ ///
670
+ /// Returns a slice of self from the beginning until but not including
671
+ /// the index `end`.
672
+ ///
673
+ /// Equivalent to `&mut self[0 .. end]`
628
674
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
629
675
impl < T > ops:: IndexMut < ops:: RangeTo < usize > > for [ T ] {
630
676
#[ inline]
631
677
fn index_mut ( & mut self , index : ops:: RangeTo < usize > ) -> & mut [ T ] {
632
678
self . index_mut ( 0 .. index. end )
633
679
}
634
680
}
681
+
682
+ /// Implements mutable slicing with syntax `&mut self[begin ..]`.
683
+ ///
684
+ /// Returns a slice of self from and including the index `begin` until the end.
685
+ ///
686
+ /// Equivalent to `&mut self[begin .. self.len()]`
635
687
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
636
688
impl < T > ops:: IndexMut < ops:: RangeFrom < usize > > for [ T ] {
637
689
#[ inline]
@@ -640,6 +692,12 @@ impl<T> ops::IndexMut<ops::RangeFrom<usize>> for [T] {
640
692
self . index_mut ( index. start .. len)
641
693
}
642
694
}
695
+
696
+ /// Implements mutable slicing with syntax `&mut self[..]`.
697
+ ///
698
+ /// Returns a slice of the whole slice. This operation can not panic.
699
+ ///
700
+ /// Equivalent to `&mut self[0 .. self.len()]`
643
701
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
644
702
impl < T > ops:: IndexMut < RangeFull > for [ T ] {
645
703
#[ inline]
0 commit comments