String trim_start_matches() docs unclear about behaviour if &str is passed #56891
Labels
A-docs
Area: documentation for any part of the project, including the compiler, standard library, and tools
The documentation for the trim_start_matches() method on String (https://doc.rust-lang.org/std/primitive.str.html#method.trim_start_matches) says "Returns a string slice with all prefixes that match a pattern repeatedly removed. The pattern can be a &str, char, or a closure that determines if a character matches." but it doesn't describe what the behaviour of passing an &str is. I can think of two plausible behaviours: (1) if you pass in "bar" then a leading "bar" is trimmed, turning "barbaz" into "bar", or (2) the string defines the set of characters to be stripped, so "barbaz" turns into "ba", and "rabble" turns into "le". None of the examples demonstrate the &str version.
Following the link to https://doc.rust-lang.org/std/str/pattern/trait.Pattern.html suggests it may be (1), but it would be nice not to have to chase links, and also the Pattern docs have big "nightly only" warnings which leaves me unsure whether they apply to trim_start_matches(), which is not so marked.
Adding a simple example that uses the &str version of the function would probably clear this up.
The text was updated successfully, but these errors were encountered: