rust-lang / rust-lang/libs-team

`type range::RangeOfBounds<T> = (Bound<T>, Bound<T>)`

Open
#873 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

api-change-proposal
Dominant language
Rust
Stars
178
Forks
28
Avg merge
15m
Merged PRs (30d)
1

Description

Proposal

Problem statement

Our range type zoo currently does not cover some cases such as an exclusive-inclusive range or or a type that can flexibly express all cases. In some places the (Bound<T>, Bound<T>) tuple is used as the most type, for general example by the RangeBounds and IntoBounds.

Motivating examples or use cases

For example in https://github.com/rust-lang/rust/pull/162110 it was proposed to add the language

Use (Bound<T>, Bound<T>) if you need a type that can store an arbitrary range.

to Range documentation. It would be better if we could instead point to the std::range module and let users choose an appropriate type. But that requires having the most-general type on that page too.

Solution sketch

Add a type-alias to the range module that exists as a home for documentation and less cumbersome naming for general ranges.

mod range {
   /// Dedicated documentation...
   type RangeOfBounds<T> = (Bound<T>, Bound<T>);
}

The rustdoc page would also show a more-relevant subset of implementations that currently live on the tuple-primitive page

For now I'm not proposing to add any methods to this type alias since those could conflict with more general tuple methods, but with inherent trait impls we could make RangeBounds inherent so users can call contains and is_empty without importing it.

Alternatives

  • do nothing
  • don't add the alias but mention it in module-level documentation and link to the tuple page
  • introduce a dedicated type and migrate to it

Links and related work

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 reading the std::range documentation and the existing RangeBounds and IntoBounds APIs, then compare the tuple-primitive documentation linked in the proposal. Determine whether a documented RangeOfBounds alias is preferable to module-level links or a dedicated type, and seek library-team agreement before implementation.

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
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.