-
Notifications
You must be signed in to change notification settings - Fork 13.9k
Description
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.:
let mut split = "Mary had a little lamb".split(' ');
assert_eq!(split.remainder(), Some("Mary had a little lamb"));
_ = split.next();
assert_eq!(split.remainder(), Some("had a little lamb"));
split.by_ref().for_each(drop);
assert_eq!(split.remainder(), None);The feature gates for the issue are #![feature(str_split_remainder)] (for most split iterators), #![feature(str_split_inclusive_remainder)] (for SplitInclusive) and #![feature(str_split_whitespace_remainder)] (for SplitWhitespace and SplitAsciiWhitespace).
Public API
// mod core::str
impl<'a, P: Pattern<'a>> Split<'a, P> {
fn remainder(&self) -> Option<&'a str>;
}
// And the same for
// - `RSplit<'a, P>`
// - `SplitTerminator<'a, P>`
// - `RSplitTerminator<'a, P>`
// - `SplitN<'a, P>`
// - `RSplitN<'a, P>`
// - `SplitWhitespace<'a>`
// - `SplitAsciiWhitespace<'a>`
// - `SplitInclusive<'a, P>`Steps
- Implement the feature
- Adjust documentation (see instructions on rustc-dev-guide)
- Stabilization PR (see instructions on rustc-dev-guide)
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_strmethods #75265 (comment))Noneis now returned instead of an empty string, making this irrelevant
Implementation history
-
Add
str::{Split,RSplit,SplitN,RSplitN,SplitTerminator,RSplitTerminator,SplitInclusive}::as_strmethods #75265 — implementedas_strmethods oncore::str::{Split,RSplit,SplitN,RSplitN,SplitTerminator,RSplitTerminator,SplitInclusive} -
Add
as_strmethod for split whitespace str iterators #82570 — implementedas_strmethods oncore::str::{SplitWhitespace, SplitAsciiWhitespace} -
Split*::as_strrefactor #95644 — renamedas_str=>remainderand changed return type toOption<&str>