@@ -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
///
@@ -540,14 +540,10 @@ impl<T> [T] {
540
540
///
541
541
/// ```
542
542
/// let x = &mut [1, 2, 4];
543
- /// {
544
- /// let iterator = x.iter_mut();
545
- ///
546
- /// for elem in iterator {
547
- /// *elem += 2;
548
- /// }
543
+ /// for elem in x.iter_mut() {
544
+ /// *elem += 2;
549
545
/// }
550
- /// assert_eq!(x, & [3, 4, 6]);
546
+ /// assert_eq!(x, [3, 4, 6]);
551
547
/// ```
552
548
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
553
549
#[ inline]
@@ -880,7 +876,7 @@ impl<T> [T] {
880
876
core_slice:: SliceExt :: rsplitn_mut ( self , n, pred)
881
877
}
882
878
883
- /// Returns true if the slice contains an element with the given value.
879
+ /// Returns ` true` if the slice contains an element with the given value.
884
880
///
885
881
/// # Examples
886
882
///
@@ -896,7 +892,7 @@ impl<T> [T] {
896
892
core_slice:: SliceExt :: contains ( self , x)
897
893
}
898
894
899
- /// Returns true if `needle` is a prefix of the slice.
895
+ /// Returns ` true` if `needle` is a prefix of the slice.
900
896
///
901
897
/// # Examples
902
898
///
@@ -907,14 +903,23 @@ impl<T> [T] {
907
903
/// assert!(!v.starts_with(&[50]));
908
904
/// assert!(!v.starts_with(&[10, 50]));
909
905
/// ```
906
+ ///
907
+ /// Always returns `true` if `needle` is an empty slice:
908
+ ///
909
+ /// ```
910
+ /// let v = &[10, 40, 30];
911
+ /// assert!(v.starts_with(&[]));
912
+ /// let v: &[u8] = &[];
913
+ /// assert!(v.starts_with(&[]));
914
+ /// ```
910
915
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
911
916
pub fn starts_with ( & self , needle : & [ T ] ) -> bool
912
917
where T : PartialEq
913
918
{
914
919
core_slice:: SliceExt :: starts_with ( self , needle)
915
920
}
916
921
917
- /// Returns true if `needle` is a suffix of the slice.
922
+ /// Returns ` true` if `needle` is a suffix of the slice.
918
923
///
919
924
/// # Examples
920
925
///
@@ -925,6 +930,15 @@ impl<T> [T] {
925
930
/// assert!(!v.ends_with(&[50]));
926
931
/// assert!(!v.ends_with(&[50, 30]));
927
932
/// ```
933
+ ///
934
+ /// Always returns `true` if `needle` is an empty slice:
935
+ ///
936
+ /// ```
937
+ /// let v = &[10, 40, 30];
938
+ /// assert!(v.ends_with(&[]));
939
+ /// let v: &[u8] = [];
940
+ /// assert!(v.ends_with(&[]));
941
+ /// ```
928
942
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
929
943
pub fn ends_with ( & self , needle : & [ T ] ) -> bool
930
944
where T : PartialEq
0 commit comments