Skip to content

rand_core: relax requirements on the param for SeedableRng #1641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 4 additions & 0 deletions rand_core/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased
### API changes
- Relax `Sized` bound on impls of `SeedableRng` (#1641)

## [0.9.3] — 2025-02-29
### Other
- Remove `zerocopy` dependency (#1607)
Expand Down
8 changes: 4 additions & 4 deletions rand_core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng<R> {
}

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

#[inline(always)]
fn try_from_rng<S: TryRngCore>(rng: &mut S) -> Result<Self, S::Error> {
fn try_from_rng<S: TryRngCore + ?Sized>(rng: &mut S) -> Result<Self, S::Error> {
R::try_from_rng(rng).map(Self::new)
}
}
Expand Down Expand Up @@ -411,12 +411,12 @@ impl<R: BlockRngCore + SeedableRng> SeedableRng for BlockRng64<R> {
}

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

#[inline(always)]
fn try_from_rng<S: TryRngCore>(rng: &mut S) -> Result<Self, S::Error> {
fn try_from_rng<S: TryRngCore + ?Sized>(rng: &mut S) -> Result<Self, S::Error> {
R::try_from_rng(rng).map(Self::new)
}
}
Expand Down
4 changes: 2 additions & 2 deletions rand_core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ pub trait SeedableRng: Sized {
/// (in prior versions this was not required).
///
/// [`rand`]: https://docs.rs/rand
fn from_rng(rng: &mut impl RngCore) -> Self {
fn from_rng<R: RngCore + ?Sized>(rng: &mut R) -> Self {
let mut seed = Self::Seed::default();
rng.fill_bytes(seed.as_mut());
Self::from_seed(seed)
Expand All @@ -528,7 +528,7 @@ pub trait SeedableRng: Sized {
/// Create a new PRNG seeded from a potentially fallible `Rng`.
///
/// See [`from_rng`][SeedableRng::from_rng] docs for more information.
fn try_from_rng<R: TryRngCore>(rng: &mut R) -> Result<Self, R::Error> {
fn try_from_rng<R: TryRngCore + ?Sized>(rng: &mut R) -> Result<Self, R::Error> {
let mut seed = Self::Seed::default();
rng.try_fill_bytes(seed.as_mut())?;
Ok(Self::from_seed(seed))
Expand Down