Skip to content

Rng: Uninitialized buffer support - #160365

Open
joshtriplett wants to merge 2 commits into
rust-lang:mainfrom
joshtriplett:rng-fill-buf
Open

Rng: Uninitialized buffer support#160365
joshtriplett wants to merge 2 commits into
rust-lang:mainfrom
joshtriplett:rng-fill-buf

Conversation

@joshtriplett

Copy link
Copy Markdown
Member

Since BorrowedBuf/BorrowedCursor are on their way to stabilization,
add support for uninitialized buffers in Rng.

Add a fill_buf method that takes a BorrowedCursor and fills it in.
Adapt all the system implementations accordingly.

Make fill_bytes a final fn helper, which callers can use but
trait implementations ignore in favor of implementing fill_buf.


I considered making it possible to implement either fill_bytes or fill_buf, but it doesn't seem especially likely that someone would have a fill_bytes implementation that's at all challenging to convert to fill_buf.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Aug 2, 2026
@rustbot

rustbot commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

r? @jhpratt

rustbot has assigned @jhpratt.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @ChrisDenton, libs
  • @ChrisDenton, libs expanded to 13 candidates
  • Random selection from 8 candidates

@rust-log-analyzer

This comment has been minimized.

Since `BorrowedBuf`/`BorrowedCursor` are on their way to stabilization,
add support for uninitialized buffers in `Rng`.

Add a `fill_buf` method that takes a `BorrowedCursor` and fills it in.
Adapt all the system implementations accordingly.

Make `fill_bytes` a `final fn` helper, which callers can use but
trait implementations ignore in favor of implementing `fill_buf`.

@joboet joboet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have a strong opinion on whether the only-fill_buf approach is the best, but can you confirm that T-lang is fine with using final in soon-to-be-stable API? I don't think we can retroactively remove it (since people may rely on the guarantee for soundness), so some final-shaped feature would always need to stay in the language.

View changes since this review

Comment thread library/core/src/random.rs
@joshtriplett

Copy link
Copy Markdown
Member Author

can you confirm that T-lang is fine with using final in soon-to-be-stable API?

Will do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants