rust-lang / rust-lang/rfcs

Vec::split_off should take a range

Open
#1,341 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

T-libs
Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

fn split_off(&mut self, at: usize) -> Vec<T>

should be

fn split_off(&mut self, at: Range<usize>) -> Vec<T>

Existing uses can take [n..] rather than n. This allows more flexibility - a user can split off the first half, rather than the last half, or a chunk from the middle. Clearly the suffix mode will be more efficient, but I believe we can retain efficiency in this case, and the other cases will be worse - no loss.

Alternative: have a separate method which takes a range rather than an integer. This is more API so sucks, but makes the performance characteristics more explicit.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing Vec::split_off API and the RFC process in this repository. Evaluate the proposed Range signature against suffix, prefix, and middle-chunk uses, including the stated efficiency tradeoffs and alternative API. Done means the API direction and its compatibility implications are resolved in an accepted RFC.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.