From 12410f8213fd668c5caf058afe475dbd7df0b77e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 5 Mar 2021 17:41:16 -0800 Subject: [PATCH] Update to rand 0.8 and release 0.4.0 --- Cargo.toml | 4 ++-- README.md | 4 ++-- RELEASES.md | 6 ++++++ src/crand.rs | 37 +++++++++++++++++++++++++++++++++++-- src/lib.rs | 2 +- 5 files changed, 46 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 70502b4..4152e0d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ categories = ["algorithms", "data-structures", "science", "no-std"] license = "MIT OR Apache-2.0" name = "num-complex" repository = "https://github.com/rust-num/num-complex" -version = "0.3.1" +version = "0.4.0" readme = "README.md" exclude = ["/bors.toml", "/ci/*", "/.github/*"] edition = "2018" @@ -30,7 +30,7 @@ default-features = false [dependencies.rand] optional = true -version = "0.7" +version = "0.8" default-features = false [features] diff --git a/README.md b/README.md index f1754b2..fdb1d38 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Add this to your `Cargo.toml`: ```toml [dependencies] -num-complex = "0.3" +num-complex = "0.4" ``` ## Features @@ -23,7 +23,7 @@ the default `std` feature. Use this in `Cargo.toml`: ```toml [dependencies.num-complex] -version = "0.3" +version = "0.4" default-features = false ``` diff --git a/RELEASES.md b/RELEASES.md index a84ca96..f3f0e95 100644 --- a/RELEASES.md +++ b/RELEASES.md @@ -1,3 +1,9 @@ +# Release 0.4.0 (2021-03-05) + +- `rand` support has been updated to 0.8, requiring Rust 1.36. + +**Contributors**: @cuviper + # Release 0.3.1 (2020-10-29) - Clarify the license specification as "MIT OR Apache-2.0". diff --git a/src/crand.rs b/src/crand.rs index 6df2ff4..5edf8a7 100644 --- a/src/crand.rs +++ b/src/crand.rs @@ -42,8 +42,41 @@ where } #[cfg(test)] -fn test_rng() -> StdRng { - StdRng::from_seed([42; 32]) +fn test_rng() -> impl RngCore { + /// Simple `Rng` for testing without additional dependencies + struct XorShiftStar { + a: u64, + } + + impl RngCore for XorShiftStar { + fn next_u32(&mut self) -> u32 { + self.next_u64() as u32 + } + + fn next_u64(&mut self) -> u64 { + // https://en.wikipedia.org/wiki/Xorshift#xorshift* + self.a ^= self.a >> 12; + self.a ^= self.a << 25; + self.a ^= self.a >> 27; + self.a.wrapping_mul(0x2545_F491_4F6C_DD1D) + } + + fn fill_bytes(&mut self, dest: &mut [u8]) { + for chunk in dest.chunks_mut(8) { + let bytes = self.next_u64().to_le_bytes(); + let slice = &bytes[..chunk.len()]; + chunk.copy_from_slice(slice) + } + } + + fn try_fill_bytes(&mut self, dest: &mut [u8]) -> Result<(), rand::Error> { + Ok(self.fill_bytes(dest)) + } + } + + XorShiftStar { + a: 0x0123_4567_89AB_CDEF, + } } #[test] diff --git a/src/lib.rs b/src/lib.rs index 4afa533..ca8ff11 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -14,7 +14,7 @@ //! //! The `num-complex` crate is tested for rustc 1.31 and greater. -#![doc(html_root_url = "https://docs.rs/num-complex/0.3")] +#![doc(html_root_url = "https://docs.rs/num-complex/0.4")] #![no_std] #[cfg(any(test, feature = "std"))]