Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String trim_start_matches() docs unclear about behaviour if &str is passed #56891

Closed
pm215 opened this issue Dec 16, 2018 · 2 comments
Closed
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools

Comments

@pm215
Copy link

pm215 commented Dec 16, 2018

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.

@estebank estebank added the A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools label Dec 17, 2018
@shepmaster
Copy link
Member

Duplicate of #54520

@shepmaster shepmaster marked this as a duplicate of #54520 Dec 19, 2018
@steveklabnik
Copy link
Member

Closing as duplicate, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: documentation for any part of the project, including the compiler, standard library, and tools
Projects
None yet
Development

No branches or pull requests

4 participants