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