forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#75265 - WaffleLapkin:str_split_as_str, r=dt…
…olnay Add `str::{Split,RSplit,SplitN,RSplitN,SplitTerminator,RSplitTerminator,SplitInclusive}::as_str` methods tl;dr this allows viewing unyelded part of str-split-iterators, like so: ```rust let mut split = "Mary had a little lamb".split(' '); assert_eq!(split.as_str(), "Mary had a little lamb"); split.next(); assert_eq!(split.as_str(), "had a little lamb"); split.by_ref().for_each(drop); assert_eq!(split.as_str(), ""); ``` -------------- This PR adds semi-identical `as_str` methods to most str-split-iterators with signatures like `&'_ Split<'a, P: Pattern<'a>> -> &'a str` (Note: output `&str` lifetime is bound to the `'a`, not the `'_`). The methods are similar to [`Chars::as_str`] `SplitInclusive::as_str` is under `"str_split_inclusive_as_str"` feature gate, all other methods are under `"str_split_as_str"` feature gate. Before this PR you had to sum `len`s of all yielded parts or collect into `String` to emulate `as_str`. [`Chars::as_str`]: https://doc.rust-lang.org/core/str/struct.Chars.html#method.as_str
- Loading branch information
Showing
2 changed files
with
166 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters