Closed
Description
Proposal
Add Lines::remainder
similarly to other remainder
methods on split iterators for strings (see tracking issue: rust-lang/rust#77998).
Problem statement
While most iterators that split strings allow to get the remainder, Lines
does not.
Motivation, use-cases
It may be beneficial to get the remainder of an iterator, for example to process it differently. A rough sketch:
let lines = s.lines();
while let Some(line) = lines.next() {
let command = line.parse::<Command>()?;
// ...
if command.is_end() {
process_end(lines.remainder());
break;
}
}
Solution sketches
impl<'a> Lines<'a> {
pub fn remainder(&self) -> Option<&'a str> { /* ... */ }
}
Links and related work
- Tracking issue for similar methods on other iterators: Tracking Issue for
remainder
methods forstr
split iterators rust#77998 - Implementation PR: Add
str::Lines::remainder
rust#107464
What happens now?
This issue is part of the libs-api team API change proposal process. Once this issue is filed the libs-api team will review open proposals in its weekly meeting. You should receive feedback within a week or two.