From 0f5ca2f15c8d33b5be13438ce5f1a33caa74239f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 3 Feb 2026 01:31:04 +0000 Subject: [PATCH] Upgrade to rand_core 0.10 (supports getrandom 0.4 ecosystem) Co-authored-by: youknowone <69878+youknowone@users.noreply.github.com> --- Cargo.toml | 2 +- src/lib.rs | 18 ++++++++++-------- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3906af9..25f976b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,4 +10,4 @@ repository = "https://github.com/RustPython/mt19937" rust-version = "1.85" [dependencies] -rand_core = "0.9" +rand_core = "0.10" diff --git a/src/lib.rs b/src/lib.rs index d90420f..987b2af 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -251,24 +251,26 @@ impl MT19937 { /// Original mt19937ar.c attribution: /// /** These real versions are due to Isaku Wada, 2002/01/09 added */ -pub fn gen_res53(rng: &mut R) -> f64 { +pub fn gen_res53(rng: &mut R) -> f64 { let a = rng.next_u32() >> 5; let b = rng.next_u32() >> 6; (a as f64 * 67108864.0 + b as f64) * (1.0 / 9007199254740992.0) } -impl rand_core::RngCore for MT19937 { +impl rand_core::TryRng for MT19937 { + type Error = core::convert::Infallible; + #[inline] - fn next_u32(&mut self) -> u32 { - self.gen_u32() + fn try_next_u32(&mut self) -> Result { + Ok(self.gen_u32()) } #[inline] - fn next_u64(&mut self) -> u64 { - rand_core::impls::next_u64_via_u32(self) + fn try_next_u64(&mut self) -> Result { + rand_core::utils::next_u64_via_u32(self) } #[inline] - fn fill_bytes(&mut self, dest: &mut [u8]) { - rand_core::impls::fill_bytes_via_next(self, dest) + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Self::Error> { + rand_core::utils::fill_bytes_via_next_word(dest, || self.try_next_u64()) } }