Skip to content

Commit 07a0208

Browse files
authored
rand_core: relax requirements on the param for SeedableRng (#1641)
2 parents ead83fd + 97c3e2f commit 07a0208

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
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 impls of `SeedableRng` (#1641)
10+
711
## [0.9.3] — 2025-02-29
812
### Other
913
- Remove `zerocopy` dependency (#1607)

rand_core/src/block.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,12 +248,12 @@ impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng<R> {
248248
}
249249

250250
#[inline(always)]
251-
fn from_rng(rng: &mut impl RngCore) -> Self {
251+
fn from_rng<S: RngCore + ?Sized>(rng: &mut S) -> Self {
252252
Self::new(R::from_rng(rng))
253253
}
254254

255255
#[inline(always)]
256-
fn try_from_rng<S: TryRngCore>(rng: &mut S) -> Result<Self, S::Error> {
256+
fn try_from_rng<S: TryRngCore + ?Sized>(rng: &mut S) -> Result<Self, S::Error> {
257257
R::try_from_rng(rng).map(Self::new)
258258
}
259259
}
@@ -411,12 +411,12 @@ impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng64<R> {
411411
}
412412

413413
#[inline(always)]
414-
fn from_rng(rng: &mut impl RngCore) -> Self {
414+
fn from_rng<S: RngCore + ?Sized>(rng: &mut S) -> Self {
415415
Self::new(R::from_rng(rng))
416416
}
417417

418418
#[inline(always)]
419-
fn try_from_rng<S: TryRngCore>(rng: &mut S) -> Result<Self, S::Error> {
419+
fn try_from_rng<S: TryRngCore + ?Sized>(rng: &mut S) -> Result<Self, S::Error> {
420420
R::try_from_rng(rng).map(Self::new)
421421
}
422422
}

rand_core/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ pub trait SeedableRng: Sized {
519519
/// (in prior versions this was not required).
520520
///
521521
/// [`rand`]: https://docs.rs/rand
522-
fn from_rng(rng: &mut impl RngCore) -> Self {
522+
fn from_rng<R: RngCore + ?Sized>(rng: &mut R) -> Self {
523523
let mut seed = Self::Seed::default();
524524
rng.fill_bytes(seed.as_mut());
525525
Self::from_seed(seed)
@@ -528,7 +528,7 @@ pub trait SeedableRng: Sized {
528528
/// Create a new PRNG seeded from a potentially fallible `Rng`.
529529
///
530530
/// See [`from_rng`][SeedableRng::from_rng] docs for more information.
531-
fn try_from_rng<R: TryRngCore>(rng: &mut R) -> Result<Self, R::Error> {
531+
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
532532
let mut seed = Self::Seed::default();
533533
rng.try_fill_bytes(seed.as_mut())?;
534534
Ok(Self::from_seed(seed))

0 commit comments

Comments
 (0)