Skip to content

Tracking issue for [T]::rsplit and [T]::rsplit_mut #41020

Closed
@jorendorff

Description

@jorendorff

Update (@SimonSapin): this is now a tracking issue for methods implemented in #41065.


In @brson's tech review of Programming Rust, when he got to the bit where we list all the slice methods, he wrote: "What about 'rsplit' (no 'n')?"

I thought, oh no, I missed a method. But there really isn't a [T]::rsplit method!

str [T]
.split(p) .split(p)
.rsplit(p) nope
.splitn(p) .splitn(p)
.rsplitn(p) .rsplitn(p)

Slices don't have .rsplit(p), I guess maybe because .split(p).rev() does exactly what .rsplit(p) would do. (The two are subtly different for strings, in cases where the pattern can have overlapping matches.)

But is that a good enough reason to "break symmetry"?

@brson either really expected rsplit to exist, or he was speaking up for a hypothetical reader, new to Rust, who might expect it. Either way, I think it should be added, just to reduce by 1 the number of curious wrinkles in libcore. I'll write an RFC if this seems reasonable.

Metadata

Metadata

Assignees

No one assigned

    Labels

    B-unstableBlocker: Implemented in the nightly compiler and unstable.C-tracking-issueCategory: An issue tracking the progress of sth. like the implementation of an RFCT-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.final-comment-periodIn the final comment period and will be merged soon unless new substantive objections are raised.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions