@@ -1160,6 +1160,12 @@ impl str {
1160
1160
/// The [pattern] can be a `&str`, [`char`], a slice of [`char`]s, or a
1161
1161
/// function or closure that determines if a character matches.
1162
1162
///
1163
+ /// Note that there is a footgun to this method when using a slice of [`char`]s.
1164
+ /// Some users may expect that a slice of chars will behave similarly to a `&str` with this method.
1165
+ /// That is not currently the case. When you pass a slice of [`char`]s to this method, it will return true
1166
+ /// if any of the [`char`]s in the slice is the first [`char`] of this string slice. It does not work for
1167
+ /// sequentially comparing a slice of [`char`]s to a string slice. See the second example below.
1168
+ ///
1163
1169
/// [`char`]: prim@char
1164
1170
/// [pattern]: self::pattern
1165
1171
///
@@ -1171,6 +1177,14 @@ impl str {
1171
1177
/// assert!(bananas.starts_with("bana"));
1172
1178
/// assert!(!bananas.starts_with("nana"));
1173
1179
/// ```
1180
+ ///
1181
+ /// ```
1182
+ /// let bananas = "bananas";
1183
+ ///
1184
+ /// // Note that both of these assert successfully.
1185
+ /// assert!(bananas.starts_with(&['b', 'a', 'n', 'a']));
1186
+ /// assert!(bananas.starts_with(&['a', 'b', 'c', 'd']));
1187
+ /// ```
1174
1188
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1175
1189
pub fn starts_with < ' a , P : Pattern < ' a > > ( & ' a self , pat : P ) -> bool {
1176
1190
pat. is_prefix_of ( self )
0 commit comments