-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Expand examples on str functions #54520
Comments
Why don't you submit a PR ;) It's a very good and easy topic to work on |
https://doc.rust-lang.org/std/primitive.str.html#method.contains Here's the current example we have: let bananas = "bananas";
assert!(bananas.contains("nana"));
assert!(!bananas.contains("apples")); What does |
it shows you can use single characters and stuff? |
Do you also suggest adding examples using a closure? I think it would be better to highlight that these functions take a |
Also worth noting that |
the documentation for this is in |
The most salient feature of the Pattern documentation is all the "nightly only", "nightly only" warnings in it. I think it would be better to be able to understand the documentation for non-nightly features without having to look at documentation that is so marked. Also in general, if you're relatively new to Rust, I think it's much easier to understand a concrete example than to follow a link to a page documenting an abstract Trait and then have to figure out how the trait applies to the particular situation you were interested in. More examples in the Pattern page itself would probably help too. |
https://doc.rust-lang.org/std/primitive.str.html#method.split
Examples
I honstely think there are more than enough code examples all with explanation. If you think we are missing something, please feel free to suggest one or open a PR and add one. We are looking forward to it! |
Yes, the split method has a good set of examples. I'm here because I started at the trim_start_matches method, which doesn't so much. I raised a bug (#56891); it was merged with this one; estebank filed a PR #56898 which I think would be fine as a fix for it; shepmaster commented on that PR saying they were against merging it; so I'm here trying to argue the case for being a bit more verbose with the examples. |
To be clear, I'm only one voice; others may (and probably do) disagree with me. I'm mostly arguing from a maintenance perspective; this request is the equivalent of "inline the |
The problem is that Pattern is nightly-only, and the docs aren't written to reflect Pattern matching but instead give examples based on concrete impls. |
I agree with this in general, but it's not an uncommon occurrence. Examples off the top of my head...
I'd prefer to have some solution that can address all cases of this. |
All of those cases are used once or only a few times, and as such are allowed to rely on concrete stuff for the docs. The problem with Pattern is that it's used MANY times... Hmm. I wonder if we could boil everything down to one or two core Pattern-using things and describe everything else as a combination of them, so that inlining Pattern's docs only needs to happen a handful of times... |
Personally I think that making users aware that a Maybe we can find some middle ground by linking the examples to Pattern more clearly but also stating that Pattern is implemented by |
Also be aware of RFC 2005, which enhances |
@shepmaster Thanks for the advice, do you think it would be wise to wait with writing any documentation as that might soon be replaced with the Needle API? Or do you suspect that that will still take a while? |
@shepmaster I hope you're still willing to respond to my previous comment here! :) Then I can either start writing some documentation or we can maybe wait for Needle to come through. (Y) |
I don't expect it to be anytime soon — @kennytm do you have any feelings about when it might occur? |
Functions like contains, starts_with, ends_with, match_indices, etc could use more examples, for example
foo.contains('\n')
(check if a string contains newlines).find, split, matches, trim_matches, etc all have them.
The text was updated successfully, but these errors were encountered: