@@ -1157,8 +1157,13 @@ impl str {
1157
1157
///
1158
1158
/// Returns `false` if it does not.
1159
1159
///
1160
- /// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
1160
+ /// The [pattern] can be a `&str`, in which case this function will return true if
1161
+ /// the `&str` is a prefix of this string slice.
1162
+ ///
1163
+ /// The [pattern] can also be a [`char`], a slice of [`char`]s, or a
1161
1164
/// function or closure that determines if a character matches.
1165
+ /// These will only be checked against the first character of this string slice.
1166
+ /// Look at the second example below regarding behavior for slices of [`char`]s.
1162
1167
///
1163
1168
/// [`char`]: prim@char
1164
1169
/// [pattern]: self::pattern
@@ -1171,6 +1176,14 @@ impl str {
1171
1176
/// assert!(bananas.starts_with("bana"));
1172
1177
/// assert!(!bananas.starts_with("nana"));
1173
1178
/// ```
1179
+ ///
1180
+ /// ```
1181
+ /// let bananas = "bananas";
1182
+ ///
1183
+ /// // Note that both of these assert successfully.
1184
+ /// assert!(bananas.starts_with(&['b', 'a', 'n', 'a']));
1185
+ /// assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
1186
+ /// ```
1174
1187
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1175
1188
pub fn starts_with < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> bool {
1176
1189
pat. is_prefix_of ( self )
0 commit comments