diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index adf52a8..1e8d6ce 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -54,7 +54,7 @@ jobs: - os: ubuntu-latest target: x86_64-unknown-linux-gnu variant: MSRV - toolchain: 1.63.0 + toolchain: 1.85.0 - os: ubuntu-latest deps: sudo apt-get update ; sudo apt install gcc-multilib target: i686-unknown-linux-gnu diff --git a/CHANGELOG.md b/CHANGELOG.md index 64def47..20d366d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,13 +4,15 @@ 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] +## [0.5.0] - 2026-02-02 -- Rename `Seeder::make_rng` → `Seeder::into_rng` +- Bump MSRV to 1.85.0 (#22) +- Update to `rand_core` v0.10 (#22) ## [0.4.0] - 2025-01-27 - Update to `rand_core` v0.9 +- Rename `Seeder::make_rng` → `Seeder::into_rng` (#11) ## [0.3.0] - 2024-07-31 diff --git a/Cargo.toml b/Cargo.toml index 6c76818..cc56b6c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rand_seeder" -version = "0.4.0" # NB: When modifying, also modify html_root_url in lib.rs +version = "0.5.0" # NB: When modifying, also modify html_root_url in lib.rs authors = ["The Rand Project Developers"] license = "MIT OR Apache-2.0" readme = "README.md" @@ -12,11 +12,11 @@ A universal random number seeder based on SipHash. """ keywords = ["random", "rng", "seeder"] categories = ["algorithms", "no-std"] -edition = "2021" -rust-version = "1.63" +edition = "2024" +rust-version = "1.85.0" [dependencies] -rand_core = { version = "0.9.0", default-features = false } +rand_core = { version = "0.10.0", default-features = false } [lints.clippy] unit_arg = "allow" diff --git a/benches/mod.rs b/benches/mod.rs index 8ba760c..29d2b90 100644 --- a/benches/mod.rs +++ b/benches/mod.rs @@ -15,9 +15,9 @@ const RAND_BENCH_N: u64 = 1000; const BYTES_LEN: usize = 1024; use std::mem::size_of; -use test::{black_box, Bencher}; +use test::{Bencher, black_box}; -use rand_seeder::rand_core::RngCore; +use rand_seeder::rand_core::Rng; use rand_seeder::{Seeder, SipRng}; #[bench] diff --git a/examples/seedrng.rs b/examples/seedrng.rs index f188fe3..d82e0e0 100644 --- a/examples/seedrng.rs +++ b/examples/seedrng.rs @@ -7,8 +7,8 @@ extern crate rand_seeder; -use rand_seeder::rand_core::RngCore; use rand_seeder::SipHasher; +use rand_seeder::rand_core::Rng; use std::env; use std::hash::Hasher; diff --git a/src/lib.rs b/src/lib.rs index 1726022..4aa7a54 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -23,7 +23,7 @@ //! # Example //! //! ``` -//! use rand_seeder::rand_core::RngCore; +//! use rand_seeder::rand_core::Rng; //! use rand_seeder::SipRng; // or any RNG supporting SeedableRng //! use rand_seeder::Seeder; //! @@ -38,7 +38,7 @@ #![doc( html_logo_url = "https://www.rust-lang.org/logos/rust-logo-128x128-blk.png", html_favicon_url = "https://www.rust-lang.org/favicon.ico", - html_root_url = "https://docs.rs/rand_seeder/0.4.0" + html_root_url = "https://docs.rs/rand_seeder/0.5.0" )] #![deny(missing_docs)] #![deny(missing_debug_implementations)] @@ -52,7 +52,7 @@ mod sip; pub use sip::{SipHasher, SipRng}; use core::hash::Hash; -use rand_core::{RngCore, SeedableRng}; +use rand_core::{Rng, SeedableRng}; /// A simple interface for universal seeding /// @@ -69,7 +69,7 @@ use rand_core::{RngCore, SeedableRng}; /// ```rust /// # extern crate rand_core; /// # extern crate rand_seeder; -/// use rand_core::RngCore; +/// use rand_core::Rng; /// use rand_seeder::{Seeder, SipRng}; /// /// // Use any R: SeedableRng you like in place of SipRng: diff --git a/src/sip.rs b/src/sip.rs index 159d476..4d5589a 100644 --- a/src/sip.rs +++ b/src/sip.rs @@ -17,7 +17,7 @@ use core::marker::PhantomData; use core::{cmp, hash, mem, ptr, slice}; -use rand_core::{impls, le, RngCore, SeedableRng}; +use rand_core::{Infallible, Rng, SeedableRng, TryRng, utils}; /// A portable implementation of SipHash 2-4. /// @@ -82,9 +82,7 @@ struct State { } macro_rules! compress { - ($state:expr) => {{ - compress!($state.v0, $state.v1, $state.v2, $state.v3) - }}; + ($state:expr) => {{ compress!($state.v0, $state.v1, $state.v2, $state.v3) }}; ($v0:expr, $v1:expr, $v2:expr, $v3:expr) => {{ $v0 = $v0.wrapping_add($v1); $v1 = $v1.rotate_left(13); @@ -181,23 +179,25 @@ impl SipRng { } } -impl RngCore for SipRng { - fn next_u32(&mut self) -> u32 { +impl TryRng for SipRng { + type Error = Infallible; + + fn try_next_u32(&mut self) -> Result { // Lazy way to implement. Good enough for seeding RNGs. - self.next_u64() as u32 + Ok(self.next_u64() as u32) } - fn next_u64(&mut self) -> u64 { + fn try_next_u64(&mut self) -> Result { self.state.v2 ^= self.adj; self.adj = self.adj.wrapping_sub(0x11); Sip24Rounds::c_rounds(&mut self.state); - self.state.v0 ^ self.state.v1 ^ self.state.v2 ^ self.state.v3 + Ok(self.state.v0 ^ self.state.v1 ^ self.state.v2 ^ self.state.v3) } - fn fill_bytes(&mut self, dest: &mut [u8]) { - impls::fill_bytes_via_next(self, dest) + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), Infallible> { + utils::fill_bytes_via_next_word(dest, || self.try_next_u64()) } } @@ -205,8 +205,7 @@ impl SeedableRng for SipRng { type Seed = [u8; 32]; fn from_seed(seed: Self::Seed) -> Self { - let mut keys = [0u64; 4]; - le::read_u64_into(&seed, &mut keys); + let keys: [u64; 4] = utils::read_words(&seed); SipRng::from_state(State { v0: keys[0], v1: keys[1],