core lib request: Add a count/length method to `core::range::Range`
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
The old core::ops::Range was an iterator directly, so you could check the count with r.count(). On the new range type you can't easily check the count / length of the range (eg: to compare it to the length of a string when you're unit testing your parser). writing r.into_iter().count() seems a little overkill to me.
I do understand that the point of the new Range is to not natively be an iterator so that it can be Copy, but it still logically has a length to it, and checking that length is a non-destructive step, so having this method built directly onto the type shouldn't break anyone's assumptions on accident, and it seems completely in the spirit of the existing is_empty method.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the core::range::Range entry point and compare the requested query with the existing is_empty method. Resolve whether the API should be named count or length and define its behavior for representative ranges; done means the non-destructive query is available with coverage for those cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 65/100