@@ -181,7 +181,7 @@ impl<T> [T] {
181
181
core_slice:: SliceExt :: len ( self )
182
182
}
183
183
184
- /// Returns true if the slice has a length of 0.
184
+ /// Returns ` true` if the slice has a length of 0.
185
185
///
186
186
/// # Example
187
187
///
@@ -549,12 +549,8 @@ impl<T> [T] {
549
549
///
550
550
/// ```
551
551
/// let x = &mut [1, 2, 4];
552
- /// {
553
- /// let iterator = x.iter_mut();
554
- ///
555
- /// for elem in iterator {
556
- /// *elem += 2;
557
- /// }
552
+ /// for elem in x.iter_mut() {
553
+ /// *elem += 2;
558
554
/// }
559
555
/// assert_eq!(x, &[3, 4, 6]);
560
556
/// ```
@@ -889,7 +885,7 @@ impl<T> [T] {
889
885
core_slice:: SliceExt :: rsplitn_mut ( self , n, pred)
890
886
}
891
887
892
- /// 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.
893
889
///
894
890
/// # Examples
895
891
///
@@ -905,7 +901,7 @@ impl<T> [T] {
905
901
core_slice:: SliceExt :: contains ( self , x)
906
902
}
907
903
908
- /// Returns true if `needle` is a prefix of the slice.
904
+ /// Returns ` true` if `needle` is a prefix of the slice.
909
905
///
910
906
/// # Examples
911
907
///
@@ -916,14 +912,23 @@ impl<T> [T] {
916
912
/// assert!(!v.starts_with(&[50]));
917
913
/// assert!(!v.starts_with(&[10, 50]));
918
914
/// ```
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
+ /// ```
919
924
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
920
925
pub fn starts_with ( & self , needle : & [ T ] ) -> bool
921
926
where T : PartialEq
922
927
{
923
928
core_slice:: SliceExt :: starts_with ( self , needle)
924
929
}
925
930
926
- /// Returns true if `needle` is a suffix of the slice.
931
+ /// Returns ` true` if `needle` is a suffix of the slice.
927
932
///
928
933
/// # Examples
929
934
///
@@ -934,6 +939,15 @@ impl<T> [T] {
934
939
/// assert!(!v.ends_with(&[50]));
935
940
/// assert!(!v.ends_with(&[50, 30]));
936
941
/// ```
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
+ /// ```
937
951
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
938
952
pub fn ends_with ( & self , needle : & [ T ] ) -> bool
939
953
where T : PartialEq
0 commit comments