rust-random / rust-random/rand

Extend the `impl_sample_range_u` to implement the new `std/core::range::Range*` types.

Open
#1,784 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

P-postpone
Dominant language
Rust
Stars
2.1k
Forks
512
Avg merge
3d 9h
Merged PRs (30d)
7

Description

Background

What is your motivation?

Rust 1.96.0 introduced new Range types, and I'd like to use SampleRange for them.

What type of application is this? (E.g. cryptography, game, numerical simulation)

Nothing specific, more related to API surface.

Feature request

Extend the impl_sample_range_u so that they also implement SampleRange for for core::range::RangeToInclusive, core::range::RangeToInclusiveIter, core::range::RangeFromcore::range::RangeFromIter, core::range::Range, core::range::RangeIter

One concern is that we'd have to do something to only include this code when the Rust compiler is new enough.

We can use a feature to manually enable the impl, which would be the easiest. It wouldn't break consumers on <1.96.0, and for consumers >=1.96.0 they'd have to enable it manually. Or if we'd like to have it automatically we can use https://crates.io/crates/version_check or https://crates.io/crates/rustversion to guard it against Rust's version.

Thankfully range already has edition = 2024, so that's not blocking us.

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 impl_sample_range_u and the existing SampleRange implementations to understand how range types are handled. Then inspect the crate's compiler-version or feature-gating approach; done means the listed Range and Range iterator types implement SampleRange without breaking consumers on older Rust versions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.