Skip to content

Conversation

@dhardy
Copy link
Member

@dhardy dhardy commented Jan 12, 2026

  • Added a CHANGELOG.md entry

Summary

Revise the core traits according to @newpavlov's suggestion and similar to #41 but keeping the infallible methods.

No trait renames are done in this PR. Also not sure if we need any.

Details

  • TryRngCore is implemented for any R: DerefMut where Target: TryRngCore.
  • RngCore: TryRngCore<Error = Infallible> with automatic implementation over TryRngCore
  • UnwrapMut is removed
  • CryptoRng = RngCore + TryCryptoRng or as close as possible without sum traits; it is kept since I believe some people need dyn CryptoRng
  • utils::{next_u64_via_u32, next_word_via_fill} now use closures instead of R: RngCore

Questions

Should utils fns support potentially-fallible uses (try_next_u64_via_u32 takes FnMut() -> Result<u32; E> for generic E)? I think unnecessary.

@dhardy dhardy mentioned this pull request Jan 12, 2026
3 tasks
@dhardy
Copy link
Member Author

dhardy commented Jan 13, 2026

Updated. Some things need further discussion (see above).

@dhardy dhardy changed the title Let RngCore: TryRngCore Let RngCore: TryRngCore<Error = Infallible> Jan 14, 2026
@dhardy dhardy merged commit 48d9605 into master Jan 14, 2026
13 checks passed
@dhardy dhardy deleted the push-zqznkttsmlvp branch January 14, 2026 18:37
tarcieri pushed a commit to RustCrypto/traits that referenced this pull request Jan 19, 2026
This fixes changes made in #2195

This is due to the refactor made in rand_core in
rust-random/rand_core#45 which dropped the
"trait dependency" between CryptoRng and RngCore
@tarcieri
Copy link

We noticed something a little weird here:

So:

pub trait CryptoRng: TryCryptoRng<Error = Infallible> {}
impl<R: TryRngCore<Error = Infallible>> RngCore for R { ...

I would expect that means any type which impls CryptoRng also impls RngCore, but in RustCrypto/traits#2197 we had to add explicit RngCore bounds (or reborrow as in RustCrypto/traits#2195)

@newpavlov
Copy link
Member

I guess we should revert my suggestion above and add a test for this.

@tarcieri
Copy link

I don't get it... I tried to make a contrived version in the playground and it... works?

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=be7a3fdc3b7bc93fb22c1529d99d4f03

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants