From 26c65c598783e1f30c5dc1137c5943d6e77fe07d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Stankovi=C4=87?= Date: Fri, 23 May 2025 14:14:10 +0200 Subject: [PATCH 1/4] chore: update dependencies to latest versions In particular, wyhash has been released which moves to rand 0.9, which brings quite a few of breaking changes. Luckily, we don't depend on it too much so the move is trivial. --- Cargo.toml | 10 +++++----- benches/bench.rs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 64249ff..ae07273 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,16 +21,16 @@ std = ["alloc"] js = ["std", "getrandom"] [target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dependencies] -getrandom = { version = "0.2", features = ["js"], optional = true } +getrandom = { version = "0.3", features = ["wasm_js"], optional = true } [target.'cfg(all(any(target_arch = "wasm32", target_arch = "wasm64"), target_os = "unknown"))'.dev-dependencies] wasm-bindgen-test = "0.3" -getrandom = { version = "0.2", features = ["js"] } +getrandom = { version = "0.3", features = ["wasm_js"] } [dev-dependencies] -rand = "0.8" -wyhash = "0.5" -getrandom = "0.2" +rand = "0.9" +wyhash = "0.6" +getrandom = "0.3" [package.metadata.docs.rs] all-features = true diff --git a/benches/bench.rs b/benches/bench.rs index 72da348..1e2d200 100644 --- a/benches/bench.rs +++ b/benches/bench.rs @@ -8,7 +8,7 @@ use wyhash::WyRng; #[bench] fn shuffle_wyhash(b: &mut Bencher) { - let mut rng = WyRng::from_rng(thread_rng()).unwrap(); + let mut rng = WyRng::from_rng(&mut rand::rng()); let mut x = (0..100).collect::>(); b.iter(|| { x.shuffle(&mut rng); @@ -28,11 +28,11 @@ fn shuffle_fastrand(b: &mut Bencher) { #[bench] fn u8_wyhash(b: &mut Bencher) { - let mut rng = WyRng::from_rng(thread_rng()).unwrap(); + let mut rng = WyRng::from_rng(&mut rand::rng()); b.iter(|| { let mut sum = 0u8; for _ in 0..10_000 { - sum = sum.wrapping_add(rng.gen::()); + sum = sum.wrapping_add(rng.random::()); } sum }) @@ -52,11 +52,11 @@ fn u8_fastrand(b: &mut Bencher) { #[bench] fn u32_wyhash(b: &mut Bencher) { - let mut rng = WyRng::from_rng(thread_rng()).unwrap(); + let mut rng = WyRng::from_rng(&mut rand::rng()); b.iter(|| { let mut sum = 0u32; for _ in 0..10_000 { - sum = sum.wrapping_add(rng.gen::()); + sum = sum.wrapping_add(rng.random::()); } sum }) From 42a265af3eb021f5ae4e98e7f79e8b22aa1431a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Stankovi=C4=87?= Date: Fri, 23 May 2025 14:49:12 +0200 Subject: [PATCH 2/4] ci: select the wasm_js backend for getrandom when testing wasm See https://docs.rs/getrandom/0.3.3/getrandom/#webassembly-support. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 298b2e9..5a4c354 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -70,7 +70,7 @@ jobs: # Use no-std target to ensure we don't link to std. run: cargo build --no-default-features --features alloc --target thumbv7m-none-eabi - name: Test wasm - run: wasm-pack test --headless --chrome + run: RUSTFLAGS='--cfg getrandom_backend="wasm_js"' wasm-pack test --headless --chrome if: startsWith(matrix.os, 'ubuntu') - run: cargo bench if: startsWith(matrix.rust, 'nightly') From a5945a7a751b5b49a33859998d88ea31623bd792 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Stankovi=C4=87?= Date: Fri, 23 May 2025 14:53:40 +0200 Subject: [PATCH 3/4] chore: update MSRV to 1.63 --- .github/workflows/ci.yml | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5a4c354..0050638 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,6 +88,11 @@ jobs: msrv: runs-on: ubuntu-latest + strategy: + matrix: + # When updating this, the reminder to update the minimum supported + # Rust version in Cargo.toml. + rust: ['1.63'] steps: - uses: taiki-e/checkout-action@v1 - name: Install cargo-hack diff --git a/Cargo.toml b/Cargo.toml index ae07273..671848e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,7 +6,7 @@ name = "fastrand" version = "2.3.0" authors = ["Stjepan Glavina "] edition = "2018" -rust-version = "1.36" +rust-version = "1.63" description = "A simple and fast random number generator" license = "Apache-2.0 OR MIT" repository = "https://github.com/smol-rs/fastrand" From b2da4469df39fd1066a6b342b2612ef8409ac3d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Stankovi=C4=87?= Date: Fri, 23 May 2025 14:59:11 +0200 Subject: [PATCH 4/4] chore: fix clippy warnings --- src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index cc7bc94..e394688 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -260,13 +260,13 @@ macro_rules! rng_integer { }; let low = match range.start_bound() { - Bound::Unbounded => core::$t::MIN, + Bound::Unbounded => $t::MIN, Bound::Included(&x) => x, Bound::Excluded(&x) => x.checked_add(1).unwrap_or_else(panic_empty_range), }; let high = match range.end_bound() { - Bound::Unbounded => core::$t::MAX, + Bound::Unbounded => $t::MAX, Bound::Included(&x) => x, Bound::Excluded(&x) => x.checked_sub(1).unwrap_or_else(panic_empty_range), }; @@ -275,7 +275,7 @@ macro_rules! rng_integer { panic_empty_range(); } - if low == core::$t::MIN && high == core::$t::MAX { + if low == $t::MIN && high == $t::MAX { self.$gen() as $t } else { let len = high.wrapping_sub(low).wrapping_add(1);