@@ -691,41 +691,6 @@ impl<T> [T] {
691
691
Chunks { v : self , chunk_size : chunk_size }
692
692
}
693
693
694
- /// Returns an iterator over `chunk_size` elements of the slice at a
695
- /// time. The chunks are slices and do not overlap. If `chunk_size` does
696
- /// not divide the length of the slice, then the last up to `chunk_size-1`
697
- /// elements will be omitted.
698
- ///
699
- /// Due to each chunk having exactly `chunk_size` elements, the compiler
700
- /// can often optimize the resulting code better than in the case of
701
- /// [`chunks`].
702
- ///
703
- /// # Panics
704
- ///
705
- /// Panics if `chunk_size` is 0.
706
- ///
707
- /// # Examples
708
- ///
709
- /// ```
710
- /// #![feature(exact_chunks)]
711
- ///
712
- /// let slice = ['l', 'o', 'r', 'e', 'm'];
713
- /// let mut iter = slice.exact_chunks(2);
714
- /// assert_eq!(iter.next().unwrap(), &['l', 'o']);
715
- /// assert_eq!(iter.next().unwrap(), &['r', 'e']);
716
- /// assert!(iter.next().is_none());
717
- /// ```
718
- ///
719
- /// [`chunks`]: #method.chunks
720
- #[ unstable( feature = "exact_chunks" , issue = "47115" ) ]
721
- #[ inline]
722
- pub fn exact_chunks ( & self , chunk_size : usize ) -> ExactChunks < T > {
723
- assert ! ( chunk_size != 0 ) ;
724
- let rem = self . len ( ) % chunk_size;
725
- let len = self . len ( ) - rem;
726
- ExactChunks { v : & self [ ..len] , chunk_size : chunk_size}
727
- }
728
-
729
694
/// Returns an iterator over `chunk_size` elements of the slice at a time.
730
695
/// The chunks are mutable slices, and do not overlap. If `chunk_size` does
731
696
/// not divide the length of the slice, then the last chunk will not
@@ -761,6 +726,41 @@ impl<T> [T] {
761
726
ChunksMut { v : self , chunk_size : chunk_size }
762
727
}
763
728
729
+ /// Returns an iterator over `chunk_size` elements of the slice at a
730
+ /// time. The chunks are slices and do not overlap. If `chunk_size` does
731
+ /// not divide the length of the slice, then the last up to `chunk_size-1`
732
+ /// elements will be omitted.
733
+ ///
734
+ /// Due to each chunk having exactly `chunk_size` elements, the compiler
735
+ /// can often optimize the resulting code better than in the case of
736
+ /// [`chunks`].
737
+ ///
738
+ /// # Panics
739
+ ///
740
+ /// Panics if `chunk_size` is 0.
741
+ ///
742
+ /// # Examples
743
+ ///
744
+ /// ```
745
+ /// #![feature(exact_chunks)]
746
+ ///
747
+ /// let slice = ['l', 'o', 'r', 'e', 'm'];
748
+ /// let mut iter = slice.exact_chunks(2);
749
+ /// assert_eq!(iter.next().unwrap(), &['l', 'o']);
750
+ /// assert_eq!(iter.next().unwrap(), &['r', 'e']);
751
+ /// assert!(iter.next().is_none());
752
+ /// ```
753
+ ///
754
+ /// [`chunks`]: #method.chunks
755
+ #[ unstable( feature = "exact_chunks" , issue = "47115" ) ]
756
+ #[ inline]
757
+ pub fn exact_chunks ( & self , chunk_size : usize ) -> ExactChunks < T > {
758
+ assert ! ( chunk_size != 0 ) ;
759
+ let rem = self . len ( ) % chunk_size;
760
+ let len = self . len ( ) - rem;
761
+ ExactChunks { v : & self [ ..len] , chunk_size : chunk_size}
762
+ }
763
+
764
764
/// Returns an iterator over `chunk_size` elements of the slice at a time.
765
765
/// The chunks are mutable slices, and do not overlap. If `chunk_size` does
766
766
/// not divide the length of the slice, then the last up to `chunk_size-1`
@@ -1977,35 +1977,63 @@ fn slice_index_overflow_fail() -> ! {
1977
1977
panic ! ( "attempted to index slice up to maximum usize" ) ;
1978
1978
}
1979
1979
1980
+ mod private_slice_index {
1981
+ use super :: ops;
1982
+ #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
1983
+ pub trait Sealed { }
1984
+
1985
+ #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
1986
+ impl Sealed for usize { }
1987
+ #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
1988
+ impl Sealed for ops:: Range < usize > { }
1989
+ #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
1990
+ impl Sealed for ops:: RangeTo < usize > { }
1991
+ #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
1992
+ impl Sealed for ops:: RangeFrom < usize > { }
1993
+ #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
1994
+ impl Sealed for ops:: RangeFull { }
1995
+ #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
1996
+ impl Sealed for ops:: RangeInclusive < usize > { }
1997
+ #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
1998
+ impl Sealed for ops:: RangeToInclusive < usize > { }
1999
+ }
2000
+
1980
2001
/// A helper trait used for indexing operations.
1981
- #[ unstable ( feature = "slice_get_slice" , issue = "35729 " ) ]
2002
+ #[ stable ( feature = "slice_get_slice" , since = "1.28.0 " ) ]
1982
2003
#[ rustc_on_unimplemented = "slice indices are of type `usize` or ranges of `usize`" ]
1983
- pub trait SliceIndex < T : ?Sized > {
2004
+ pub trait SliceIndex < T : ?Sized > : private_slice_index :: Sealed {
1984
2005
/// The output type returned by methods.
2006
+ #[ stable( feature = "slice_get_slice" , since = "1.28.0" ) ]
1985
2007
type Output : ?Sized ;
1986
2008
1987
2009
/// Returns a shared reference to the output at this location, if in
1988
2010
/// bounds.
2011
+ #[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
1989
2012
fn get ( self , slice : & T ) -> Option < & Self :: Output > ;
1990
2013
1991
2014
/// Returns a mutable reference to the output at this location, if in
1992
2015
/// bounds.
2016
+ #[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
1993
2017
fn get_mut ( self , slice : & mut T ) -> Option < & mut Self :: Output > ;
1994
2018
1995
2019
/// Returns a shared reference to the output at this location, without
1996
2020
/// performing any bounds checking.
2021
+ #[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
1997
2022
unsafe fn get_unchecked ( self , slice : & T ) -> & Self :: Output ;
1998
2023
1999
2024
/// Returns a mutable reference to the output at this location, without
2000
2025
/// performing any bounds checking.
2026
+ #[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
2001
2027
unsafe fn get_unchecked_mut ( self , slice : & mut T ) -> & mut Self :: Output ;
2002
2028
2003
2029
/// Returns a shared reference to the output at this location, panicking
2004
2030
/// if out of bounds.
2031
+ #[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
2005
2032
fn index ( self , slice : & T ) -> & Self :: Output ;
2006
2033
2007
2034
/// Returns a mutable reference to the output at this location, panicking
2008
2035
/// if out of bounds.
2036
+ #[ unstable( feature = "slice_index_methods" , issue = "0" ) ]
2009
2037
fn index_mut ( self , slice : & mut T ) -> & mut Self :: Output ;
2010
2038
}
2011
2039
0 commit comments