@@ -343,15 +343,24 @@ impl<T> [T] {
343
343
core_slice:: SliceExt :: last_mut ( self )
344
344
}
345
345
346
- /// Returns the element of a slice at the given index, or `None` if the
347
- /// index is out of bounds.
346
+ /// Returns a reference to an element or subslice depending on the type of
347
+ /// index.
348
+ ///
349
+ /// - If given a position, returns a reference to the element at that
350
+ /// position or [`None`] if out of bounds.
351
+ /// - If given a range, returns the subslice corresponding to that range,
352
+ /// or [`None`] if out of bounds.
353
+ ///
354
+ /// [`None`]: ../std/option/enum.Option.html#variant.None
348
355
///
349
356
/// # Examples
350
357
///
351
358
/// ```
352
359
/// let v = [10, 40, 30];
353
360
/// assert_eq!(Some(&40), v.get(1));
361
+ /// assert_eq!(Some(&[10, 40][..]), v.get(0..2));
354
362
/// assert_eq!(None, v.get(3));
363
+ /// assert_eq!(None, v.get(0..4));
355
364
/// ```
356
365
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
357
366
#[ inline]
@@ -361,7 +370,11 @@ impl<T> [T] {
361
370
core_slice:: SliceExt :: get ( self , index)
362
371
}
363
372
364
- /// Returns a mutable reference to the element at the given index.
373
+ /// Returns a mutable reference to an element or subslice depending on the
374
+ /// type of index (see [`get()`]) or [`None`] if the index is out of bounds.
375
+ ///
376
+ /// [`get()`]: #method.get
377
+ /// [`None`]: ../std/option/enum.Option.html#variant.None
365
378
///
366
379
/// # Examples
367
380
///
@@ -373,7 +386,6 @@ impl<T> [T] {
373
386
/// }
374
387
/// assert_eq!(x, &[0, 42, 2]);
375
388
/// ```
376
- /// or `None` if the index is out of bounds
377
389
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
378
390
#[ inline]
379
391
pub fn get_mut < I > ( & mut self , index : I ) -> Option < & mut I :: Output >
@@ -382,8 +394,8 @@ impl<T> [T] {
382
394
core_slice:: SliceExt :: get_mut ( self , index)
383
395
}
384
396
385
- /// Returns a pointer to the element at the given index , without doing
386
- /// bounds checking. So use it very carefully!
397
+ /// Returns a reference to an element or subslice , without doing bounds
398
+ /// checking. So use it very carefully!
387
399
///
388
400
/// # Examples
389
401
///
@@ -402,8 +414,8 @@ impl<T> [T] {
402
414
core_slice:: SliceExt :: get_unchecked ( self , index)
403
415
}
404
416
405
- /// Returns an unsafe mutable pointer to the element in index. So use it
406
- /// very carefully!
417
+ /// Returns a mutable reference to an element or subslice, without doing
418
+ /// bounds checking. So use it very carefully!
407
419
///
408
420
/// # Examples
409
421
///
0 commit comments