-
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
Tracking Issue for remainder
methods for str
split iterators
#77998
Comments
Looking at its name it isn't immediately clear what it returns. Wouldn't |
The name |
Can this be added to |
@TyPR124 as noted in the implementation PR discussion it is possible, but not trivial. Both I didn't want to complicate the original PR with this, so didn't include anything like this. I can now make a new PR that'll add the same methods to |
Update: #82570 was merged, so now |
I just had a case we're i needed to split a str: |
Note that split iterators could yield an empty str as their final item, so |
That's true, to be correct the above code should look like this:
Would be nice to have |
That sounds like a use case for the recently stabilized |
I do think that returning an Maybe |
I could add this, seems reasonable. The only question is: do we want both |
I personally think we should only have the Option version. I'm worried the For example, I recently saw someone write this as an alternative for let mut split = "hello=world".split('=');
let (key, val) = (split.next()?, split.as_str()); However, the behaviour is subtly different: |
I find the |
…r_take2, r=Amanieu `Split*::as_str` refactor I've made this patch almost a year ago, so the rename and the behavior change are in one commit, sorry 😅 This fixes rust-lang#84974, as it's required to make other changes work. This PR - Renames `as_str` method of string `Split*` iterators to `remainder` (it seems like the `as_str` name was confusing to users) - Makes `remainder` return `Option<&str>`, to distinguish between "the iterator is exhausted" and "the tail is empty", this was [required on the tracking issue](rust-lang#77998 (comment)) r? `@m-ou-se`
…r=Amanieu `Split*::as_str` refactor I've made this patch almost a year ago, so the rename and the behavior change are in one commit, sorry 😅 This fixes #84974, as it's required to make other changes work. This PR - Renames `as_str` method of string `Split*` iterators to `remainder` (it seems like the `as_str` name was confusing to users) - Makes `remainder` return `Option<&str>`, to distinguish between "the iterator is exhausted" and "the tail is empty", this was [required on the tracking issue](rust-lang/rust#77998 (comment)) r? `@m-ou-se`
as_str
method to str split iteratorsremainder
methods for str
split iterators
…r=Amanieu `Split*::as_str` refactor I've made this patch almost a year ago, so the rename and the behavior change are in one commit, sorry 😅 This fixes #84974, as it's required to make other changes work. This PR - Renames `as_str` method of string `Split*` iterators to `remainder` (it seems like the `as_str` name was confusing to users) - Makes `remainder` return `Option<&str>`, to distinguish between "the iterator is exhausted" and "the tail is empty", this was [required on the tracking issue](rust-lang/rust#77998 (comment)) r? `@m-ou-se`
What's the status wrt stabilisation? |
I noticed that
I would expect it to either include all of the whitespace or none of it (though I do understand why it behaves the way it does). This behaviour, if intended, should at least be documented. |
I needed a functionality of "split the string once on X or Y, whichever is first", and I need to know whether X or Y was first. I hoped I could use |
…ines, r=dtolnay Add `str::Lines::remainder` Based on rust-lang#98453. This PR adds `str::Lines::remainder` similarly to [other remainder function on str split iterators](rust-lang#77998).
…ines, r=dtolnay Add `str::Lines::remainder` Based on rust-lang#98453. This PR adds `str::Lines::remainder` similarly to [other remainder function on str split iterators](rust-lang#77998).
Rollup merge of rust-lang#107464 - WaffleLapkin:all_that_remains_of_lines, r=dtolnay Add `str::Lines::remainder` Based on rust-lang#98453. This PR adds `str::Lines::remainder` similarly to [other remainder function on str split iterators](rust-lang#77998).
Could this work with |
This is a tracking issue for the methods implemented in #75265 and #82570, which allow viewing the remainder of the underlying string in str-split iterators. E.g.:
The feature gates for the issue are
#![feature(str_split_remainder)]
(for most split iterators),#![feature(str_split_inclusive_remainder)]
(forSplitInclusive
) and#![feature(str_split_whitespace_remainder)]
(forSplitWhitespace
andSplitAsciiWhitespace
).Public API
Steps
Unresolved Questions
Should empty strings point to the end of the haystack, or they can be arbitrary constants? (see Addstr::{Split,RSplit,SplitN,RSplitN,SplitTerminator,RSplitTerminator,SplitInclusive}::as_str
methods #75265 (comment))None
is now returned instead of an empty string, making this irrelevantImplementation history
Add
str::{Split,RSplit,SplitN,RSplitN,SplitTerminator,RSplitTerminator,SplitInclusive}::as_str
methods #75265 — implementedas_str
methods oncore::str::{Split,RSplit,SplitN,RSplitN,SplitTerminator,RSplitTerminator,SplitInclusive}
Add
as_str
method for split whitespace str iterators #82570 — implementedas_str
methods oncore::str::{SplitWhitespace, SplitAsciiWhitespace}
Split*::as_str
refactor #95644 — renamedas_str
=>remainder
and changed return type toOption<&str>
The text was updated successfully, but these errors were encountered: