Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ pub trait RngCore: TryRngCore<Error = Infallible> {
fn fill_bytes(&mut self, dst: &mut [u8]);
}

impl<R: TryRngCore<Error = Infallible>> RngCore for R {
impl<R> RngCore for R
where
R: TryRngCore<Error = Infallible> + ?Sized,
{
#[inline]
fn next_u32(&mut self) -> u32 {
match self.try_next_u32() {
Expand All @@ -86,9 +89,9 @@ impl<R: TryRngCore<Error = Infallible>> RngCore for R {
///
/// This is a convenient trait alias for <code>[TryCryptoRng]<Error = [Infallible]></code>.
/// It is equivalent to the trait sum <code>[RngCore] + [TryCryptoRng]</code>.
pub trait CryptoRng: TryCryptoRng<Error = Infallible> {}
pub trait CryptoRng: RngCore + TryCryptoRng<Error = Infallible> {}
Comment on lines -89 to +92
Copy link
Member

Choose a reason for hiding this comment

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

Interesting that this is necessary; it seems to indicate a trait solver issue.

But simple solutions are good!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think having explicit bounds even if they're covered by a blanket impl makes the compiler errors much better, because it will tell you explicitly why the bound wasn't satisfied, whereas figuring out why a blanket impl didn't work can be a lot of red herrings


impl<R: TryCryptoRng<Error = Infallible>> CryptoRng for R {}
impl<R> CryptoRng for R where R: TryCryptoRng<Error = Infallible> + ?Sized {}

/// Base trait for random number generators and random data sources
///
Expand Down