Skip to content

Add Lines::remainder #171

@WaffleLapkin

Description

@WaffleLapkin
Member

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

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.

Activity

pitaj

pitaj commented on Jan 31, 2023

@pitaj

Seems like a fitting addition to me

JohnCSimon

JohnCSimon commented on Apr 30, 2023

@JohnCSimon
Member

@WaffleLapkin Ping from triage: Can you post your status on this PR? This has sat idle for a few months.

WaffleLapkin

WaffleLapkin commented on Apr 30, 2023

@WaffleLapkin
MemberAuthor

@JohnCSimon it is waiting on review from libs-api (either the ACP or the PR)

haberman

haberman commented on Dec 3, 2023

@haberman

Any update? I found myself wanting this method today.

WaffleLapkin

WaffleLapkin commented on Dec 10, 2023

@WaffleLapkin
MemberAuthor

@haberman still waiting on T-libs-api. They are having problems with not having enough capacity.

dtolnay

dtolnay commented on Jan 26, 2024

@dtolnay
Member

This looks good to me, and I have accepted your PR. Thanks!

added
ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)
on Jan 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    ACP-acceptedAPI Change Proposal is accepted (seconded with no objections)T-libs-apiapi-change-proposalA proposal to add or alter unstable APIs in the standard libraries

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @haberman@pitaj@dtolnay@JohnCSimon@WaffleLapkin

        Issue actions

          Add `Lines::remainder` · Issue #171 · rust-lang/libs-team