Skip to content

Commit b9aeba7

Browse files
committed
Relax Sized requirements for blanket impls
1 parent ec6d5c0 commit b9aeba7

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

rand_core/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## Unreleased
8+
### API changes
9+
- Relax `Sized` bound on blanket impls for `TryRngCore`, `TryCryptoRng`, `UnwrapErr`, and `UnwrapMut` (#1593)
10+
711
## [0.9.1] - 2025-02-16
812
### API changes
913
- Add `TryRngCore::unwrap_mut`, providing an impl of `RngCore` over `&mut rng` (#1589)

rand_core/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ pub trait TryRngCore {
254254
// Note that, unfortunately, this blanket impl prevents us from implementing
255255
// `TryRngCore` for types which can be dereferenced to `TryRngCore`, i.e. `TryRngCore`
256256
// will not be automatically implemented for `&mut R`, `Box<R>`, etc.
257-
impl<R: RngCore> TryRngCore for R {
257+
impl<R: RngCore + ?Sized> TryRngCore for R {
258258
type Error = core::convert::Infallible;
259259

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

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

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

300-
impl<R: TryRngCore> RngCore for UnwrapErr<R> {
300+
impl<R: TryRngCore + ?Sized> RngCore for UnwrapErr<R> {
301301
#[inline]
302302
fn next_u32(&mut self) -> u32 {
303303
self.0.try_next_u32().unwrap()
@@ -314,14 +314,14 @@ impl<R: TryRngCore> RngCore for UnwrapErr<R> {
314314
}
315315
}
316316

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

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

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

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

343343
/// A random number generator that can be explicitly seeded.
344344
///

0 commit comments

Comments
 (0)