@@ -118,6 +118,8 @@ pub use core::slice::{SplitMut, ChunksMut, Split};
118
118
pub use core:: slice:: { SplitN , RSplitN , SplitNMut , RSplitNMut } ;
119
119
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
120
120
pub use core:: slice:: { from_raw_parts, from_raw_parts_mut} ;
121
+ #[ unstable( feature = "slice_get_slice" , issue = "35729" ) ]
122
+ pub use core:: slice:: SliceIndex ;
121
123
122
124
////////////////////////////////////////////////////////////////////////////////
123
125
// Basic slice extension methods
@@ -353,7 +355,9 @@ impl<T> [T] {
353
355
/// ```
354
356
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
355
357
#[ 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
+ {
357
361
core_slice:: SliceExt :: get ( self , index)
358
362
}
359
363
@@ -372,7 +376,9 @@ impl<T> [T] {
372
376
/// or `None` if the index is out of bounds
373
377
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
374
378
#[ 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
+ {
376
382
core_slice:: SliceExt :: get_mut ( self , index)
377
383
}
378
384
@@ -390,7 +396,9 @@ impl<T> [T] {
390
396
/// ```
391
397
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
392
398
#[ 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
+ {
394
402
core_slice:: SliceExt :: get_unchecked ( self , index)
395
403
}
396
404
@@ -410,7 +418,9 @@ impl<T> [T] {
410
418
/// ```
411
419
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
412
420
#[ 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
+ {
414
424
core_slice:: SliceExt :: get_unchecked_mut ( self , index)
415
425
}
416
426
0 commit comments