@@ -181,7 +181,7 @@ impl<T> [T] {
181181 core_slice:: SliceExt :: len ( self )
182182 }
183183
184- /// Returns true if the slice has a length of 0.
184+ /// Returns ` true` if the slice has a length of 0.
185185 ///
186186 /// # Example
187187 ///
@@ -342,15 +342,22 @@ impl<T> [T] {
342342 core_slice:: SliceExt :: last_mut ( self )
343343 }
344344
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.
347352 ///
348353 /// # Examples
349354 ///
350355 /// ```
351356 /// let v = [10, 40, 30];
352357 /// assert_eq!(Some(&40), v.get(1));
358+ /// assert_eq!(Some(&[10, 40][..]), v.get(0..2));
353359 /// assert_eq!(None, v.get(3));
360+ /// assert_eq!(None, v.get(0..4));
354361 /// ```
355362 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
356363 #[ inline]
@@ -360,7 +367,10 @@ impl<T> [T] {
360367 core_slice:: SliceExt :: get ( self , index)
361368 }
362369
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
364374 ///
365375 /// # Examples
366376 ///
@@ -372,7 +382,6 @@ impl<T> [T] {
372382 /// }
373383 /// assert_eq!(x, &[0, 42, 2]);
374384 /// ```
375- /// or `None` if the index is out of bounds
376385 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
377386 #[ inline]
378387 pub fn get_mut < I > ( & mut self , index : I ) -> Option < & mut I :: Output >
@@ -381,8 +390,8 @@ impl<T> [T] {
381390 core_slice:: SliceExt :: get_mut ( self , index)
382391 }
383392
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!
386395 ///
387396 /// # Examples
388397 ///
@@ -401,8 +410,8 @@ impl<T> [T] {
401410 core_slice:: SliceExt :: get_unchecked ( self , index)
402411 }
403412
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!
406415 ///
407416 /// # Examples
408417 ///
@@ -540,12 +549,8 @@ impl<T> [T] {
540549 ///
541550 /// ```
542551 /// let x = &mut [1, 2, 4];
543- /// {
544- /// let iterator = x.iter_mut();
545- ///
546- /// for elem in iterator {
547- /// *elem += 2;
548- /// }
552+ /// for elem in x.iter_mut() {
553+ /// *elem += 2;
549554 /// }
550555 /// assert_eq!(x, &[3, 4, 6]);
551556 /// ```
@@ -880,7 +885,7 @@ impl<T> [T] {
880885 core_slice:: SliceExt :: rsplitn_mut ( self , n, pred)
881886 }
882887
883- /// Returns true if the slice contains an element with the given value.
888+ /// Returns ` true` if the slice contains an element with the given value.
884889 ///
885890 /// # Examples
886891 ///
@@ -896,7 +901,7 @@ impl<T> [T] {
896901 core_slice:: SliceExt :: contains ( self , x)
897902 }
898903
899- /// Returns true if `needle` is a prefix of the slice.
904+ /// Returns ` true` if `needle` is a prefix of the slice.
900905 ///
901906 /// # Examples
902907 ///
@@ -907,14 +912,23 @@ impl<T> [T] {
907912 /// assert!(!v.starts_with(&[50]));
908913 /// assert!(!v.starts_with(&[10, 50]));
909914 /// ```
915+ ///
916+ /// Always returns `true` if `needle` is an empty slice:
917+ ///
918+ /// ```
919+ /// let v = &[10, 40, 30];
920+ /// assert!(v.starts_with(&[]));
921+ /// let v: &[u8] = &[];
922+ /// assert!(v.starts_with(&[]));
923+ /// ```
910924 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
911925 pub fn starts_with ( & self , needle : & [ T ] ) -> bool
912926 where T : PartialEq
913927 {
914928 core_slice:: SliceExt :: starts_with ( self , needle)
915929 }
916930
917- /// Returns true if `needle` is a suffix of the slice.
931+ /// Returns ` true` if `needle` is a suffix of the slice.
918932 ///
919933 /// # Examples
920934 ///
@@ -925,6 +939,15 @@ impl<T> [T] {
925939 /// assert!(!v.ends_with(&[50]));
926940 /// assert!(!v.ends_with(&[50, 30]));
927941 /// ```
942+ ///
943+ /// Always returns `true` if `needle` is an empty slice:
944+ ///
945+ /// ```
946+ /// let v = &[10, 40, 30];
947+ /// assert!(v.ends_with(&[]));
948+ /// let v: &[u8] = &[];
949+ /// assert!(v.ends_with(&[]));
950+ /// ```
928951 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
929952 pub fn ends_with ( & self , needle : & [ T ] ) -> bool
930953 where T : PartialEq
0 commit comments