From ab06a8d3680d42e9a5637d1861ca996f42734410 Mon Sep 17 00:00:00 2001 From: maurges Date: Tue, 9 Jun 2026 11:49:14 +0200 Subject: [PATCH 1/2] Update to rand 0.10. Bump major version Signed-off-by: maurges --- CHANGELOG.md | 6 ++++++ Cargo.toml | 14 +++++++------- src/lib.rs | 37 ++++++++++++++++++++----------------- tests/tests.rs | 2 +- 4 files changed, 34 insertions(+), 25 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 989f1cf..36b5777 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## v0.3.0 +* BREAKING: update rand_core dep to latest `v0.10`. Replace the optional + `rand-v09` feature and re-export with `rand-v10` + +See [#5](https://github.com/survived/rand_dev/pull/5) + ## v0.2.0 * BREAKING: update rand_core dep to latest `v0.9` * POSSIBLY BREAKING: the seed is now printed to stderr instead of stdout diff --git a/Cargo.toml b/Cargo.toml index 2d7cdff..42699f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_dev" -version = "0.2.0" +version = "0.3.0" license = "MIT OR Apache-2.0" edition = "2024" @@ -10,17 +10,17 @@ keywords = ["tests", "reproducibility", "rand"] repository = "https://github.com/survived/rand_dev" [dependencies] -rand_core = { version = "0.9", features = ["os_rng"] } -rand_chacha = "0.9" -getrandom = { version = "0.3", default-features = false } +rand_core = { version = "0.10" } +rand_chacha = "0.10" +getrandom = { version = "0.4.2", default-features = false, features = ["sys_rng"] } const-hex = { version = "1", default-features = false, features = ["alloc"] } -rand = { version = "0.9", optional = true } +rand = { version = "0.10", optional = true } [dev-dependencies] -rand = "0.9" +rand = "0.10" [features] default = [] -rand-v09 = ["dep:rand"] +rand-v10 = ["dep:rand"] diff --git a/src/lib.rs b/src/lib.rs index 692348b..aa00359 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,10 +1,11 @@ #![doc = include_str!("../README.md")] -#[cfg(feature = "rand-v09")] +#[cfg(feature = "rand-v10")] pub use rand; +use getrandom::SysRng; use rand_chacha::ChaCha8Rng; -use rand_core::{CryptoRng, OsRng, RngCore, SeedableRng, TryRngCore}; +use rand_core::{Rng, SeedableRng, TryRng}; /// Reproducible random generator for tests #[derive(Debug, Clone)] @@ -28,7 +29,7 @@ impl DevRng { Err(std::env::VarError::NotUnicode(_)) => { panic!("provided seed is not a valid unicode") } - Err(std::env::VarError::NotPresent) => OsRng + Err(std::env::VarError::NotPresent) => SysRng .try_fill_bytes(&mut seed) .expect("system randomness unavailable"), } @@ -61,17 +62,19 @@ impl Default for DevRng { } } -impl RngCore for DevRng { - fn next_u32(&mut self) -> u32 { - self.0.next_u32() +impl TryRng for DevRng { + type Error = std::convert::Infallible; + + fn try_next_u32(&mut self) -> Result { + self.0.try_next_u32() } - fn next_u64(&mut self) -> u64 { - self.0.next_u64() + fn try_next_u64(&mut self) -> Result { + self.0.try_next_u64() } - fn fill_bytes(&mut self, dest: &mut [u8]) { - self.0.fill_bytes(dest) + fn try_fill_bytes(&mut self, dst: &mut [u8]) -> Result<(), Self::Error> { + self.0.try_fill_bytes(dst) } } @@ -86,21 +89,21 @@ impl SeedableRng for DevRng { DevRng(ChaCha8Rng::seed_from_u64(state)) } - fn from_rng(rng: &mut impl RngCore) -> Self { + fn from_rng(rng: &mut R) -> Self { Self(ChaCha8Rng::from_rng(rng)) } - fn try_from_rng(rng: &mut R) -> Result { + fn try_from_rng(rng: &mut R) -> Result { ChaCha8Rng::try_from_rng(rng).map(Self) } - fn from_os_rng() -> Self { - Self(ChaCha8Rng::from_os_rng()) + fn fork(&mut self) -> Self { + self.fork() } - fn try_from_os_rng() -> Result { - ChaCha8Rng::try_from_os_rng().map(Self) + fn try_fork(&mut self) -> Result { + Ok(self.fork()) } } -impl CryptoRng for DevRng {} +impl rand_core::TryCryptoRng for DevRng {} diff --git a/tests/tests.rs b/tests/tests.rs index bc3b0f2..efdebee 100644 --- a/tests/tests.rs +++ b/tests/tests.rs @@ -1,4 +1,4 @@ -use rand_core::RngCore; +use rand_core::Rng; use rand_dev::DevRng; const VAR_NAME: &str = "RUST_TESTS_SEED"; From 6319b1bde5b4521318a8da4290cdb8f75dd42728 Mon Sep 17 00:00:00 2001 From: maurges Date: Wed, 10 Jun 2026 11:26:37 +0200 Subject: [PATCH 2/2] Review suggestions + workflow fixes --- .github/workflows/rust.yml | 4 ++-- Cargo.toml | 2 +- examples/simple_usage/Cargo.toml | 2 +- examples/simple_usage/src/lib.rs | 2 +- src/lib.rs | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 17eaee7..703c92d 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -21,7 +21,7 @@ jobs: cache-on-failure: "true" - name: Check run: cargo check - check-with-rand-v09: + check-with-rand-v010: runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -29,7 +29,7 @@ jobs: with: cache-on-failure: "true" - name: Check with rand v0.9 - run: cargo check --features rand-v09 + run: cargo check --features rand-v010 tests: runs-on: ubuntu-latest steps: diff --git a/Cargo.toml b/Cargo.toml index 42699f0..b0d3acc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,4 +23,4 @@ rand = "0.10" [features] default = [] -rand-v10 = ["dep:rand"] +rand-v010 = ["dep:rand"] diff --git a/examples/simple_usage/Cargo.toml b/examples/simple_usage/Cargo.toml index e526397..b3d70c2 100644 --- a/examples/simple_usage/Cargo.toml +++ b/examples/simple_usage/Cargo.toml @@ -7,4 +7,4 @@ publish = false # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -rand_dev = { path = "../../", features = ["rand-v09"] } +rand_dev = { path = "../../", features = ["rand-v010"] } diff --git a/examples/simple_usage/src/lib.rs b/examples/simple_usage/src/lib.rs index 5df7c27..a58db19 100644 --- a/examples/simple_usage/src/lib.rs +++ b/examples/simple_usage/src/lib.rs @@ -1,6 +1,6 @@ #[cfg(test)] mod tests { - use rand_dev::{DevRng, rand::Rng}; + use rand_dev::{DevRng, rand::RngExt}; #[test] fn it_works() { diff --git a/src/lib.rs b/src/lib.rs index aa00359..aab6b9d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,6 @@ #![doc = include_str!("../README.md")] -#[cfg(feature = "rand-v10")] +#[cfg(feature = "rand-v010")] pub use rand; use getrandom::SysRng;