Skip to content

Commit

Permalink
Relax Sized requirements for blanket impls
Browse files Browse the repository at this point in the history
  • Loading branch information
fjarri committed Feb 18, 2025
1 parent ec6d5c0 commit ac8e7f1
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ pub trait TryRngCore {
// Note that, unfortunately, this blanket impl prevents us from implementing
// `TryRngCore` for types which can be dereferenced to `TryRngCore`, i.e. `TryRngCore`
// will not be automatically implemented for `&mut R`, `Box<R>`, etc.
impl<R: RngCore> TryRngCore for R {
impl<R: RngCore + ?Sized> TryRngCore for R {
type Error = core::convert::Infallible;

#[inline]
Expand Down Expand Up @@ -290,14 +290,14 @@ impl<R: RngCore> TryRngCore for R {
/// (like [`OsRng`]) or if the `default()` instance uses a strong, fresh seed.
pub trait TryCryptoRng: TryRngCore {}

impl<R: CryptoRng> TryCryptoRng for R {}
impl<R: CryptoRng + ?Sized> TryCryptoRng for R {}

/// Wrapper around [`TryRngCore`] implementation which implements [`RngCore`]
/// by panicking on potential errors.
#[derive(Debug, Default, Clone, Copy, Eq, PartialEq, Hash)]
pub struct UnwrapErr<R: TryRngCore>(pub R);
pub struct UnwrapErr<R: TryRngCore + ?Sized>(pub R);

impl<R: TryRngCore> RngCore for UnwrapErr<R> {
impl<R: TryRngCore + ?Sized> RngCore for UnwrapErr<R> {
#[inline]
fn next_u32(&mut self) -> u32 {
self.0.try_next_u32().unwrap()
Expand All @@ -314,14 +314,14 @@ impl<R: TryRngCore> RngCore for UnwrapErr<R> {
}
}

impl<R: TryCryptoRng> CryptoRng for UnwrapErr<R> {}
impl<R: TryCryptoRng + ?Sized> CryptoRng for UnwrapErr<R> {}

/// Wrapper around [`TryRngCore`] implementation which implements [`RngCore`]
/// by panicking on potential errors.
#[derive(Debug, Eq, PartialEq, Hash)]
pub struct UnwrapMut<'r, R: TryRngCore + ?Sized>(pub &'r mut R);

impl<R: TryRngCore> RngCore for UnwrapMut<'_, R> {
impl<R: TryRngCore + ?Sized> RngCore for UnwrapMut<'_, R> {
#[inline]
fn next_u32(&mut self) -> u32 {
self.0.try_next_u32().unwrap()
Expand All @@ -338,7 +338,7 @@ impl<R: TryRngCore> RngCore for UnwrapMut<'_, R> {
}
}

impl<R: TryCryptoRng> CryptoRng for UnwrapMut<'_, R> {}
impl<R: TryCryptoRng + ?Sized> CryptoRng for UnwrapMut<'_, R> {}

/// A random number generator that can be explicitly seeded.
///
Expand Down

0 comments on commit ac8e7f1

Please sign in to comment.