@@ -118,6 +118,8 @@ pub use core::slice::{SplitMut, ChunksMut, Split};
118118pub use core:: slice:: { SplitN , RSplitN , SplitNMut , RSplitNMut } ;
119119#[ stable( feature = "rust1" , since = "1.0.0" ) ]
120120pub use core:: slice:: { from_raw_parts, from_raw_parts_mut} ;
121+ #[ unstable( feature = "slice_get_slice" , issue = "35729" ) ]
122+ pub use core:: slice:: SliceIndex ;
121123
122124////////////////////////////////////////////////////////////////////////////////
123125// Basic slice extension methods
@@ -353,7 +355,9 @@ impl<T> [T] {
353355 /// ```
354356 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
355357 #[ inline]
356- pub fn get ( & self , index : usize ) -> Option < & T > {
358+ pub fn get < I > ( & self , index : I ) -> Option < & I :: Output >
359+ where I : SliceIndex < T >
360+ {
357361 core_slice:: SliceExt :: get ( self , index)
358362 }
359363
@@ -372,7 +376,9 @@ impl<T> [T] {
372376 /// or `None` if the index is out of bounds
373377 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
374378 #[ inline]
375- pub fn get_mut ( & mut self , index : usize ) -> Option < & mut T > {
379+ pub fn get_mut < I > ( & mut self , index : I ) -> Option < & mut I :: Output >
380+ where I : SliceIndex < T >
381+ {
376382 core_slice:: SliceExt :: get_mut ( self , index)
377383 }
378384
@@ -390,7 +396,9 @@ impl<T> [T] {
390396 /// ```
391397 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
392398 #[ inline]
393- pub unsafe fn get_unchecked ( & self , index : usize ) -> & T {
399+ pub unsafe fn get_unchecked < I > ( & self , index : I ) -> & I :: Output
400+ where I : SliceIndex < T >
401+ {
394402 core_slice:: SliceExt :: get_unchecked ( self , index)
395403 }
396404
@@ -410,7 +418,9 @@ impl<T> [T] {
410418 /// ```
411419 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
412420 #[ inline]
413- pub unsafe fn get_unchecked_mut ( & mut self , index : usize ) -> & mut T {
421+ pub unsafe fn get_unchecked_mut < I > ( & mut self , index : I ) -> & mut I :: Output
422+ where I : SliceIndex < T >
423+ {
414424 core_slice:: SliceExt :: get_unchecked_mut ( self , index)
415425 }
416426
0 commit comments