diff --git a/Cargo.lock b/Cargo.lock index 33852dd..3e1d860 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -8,7 +8,7 @@ version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "891477e0c6a8957309ee5c45a6368af3ae14bb510732d2684ffa19af310920f9" dependencies = [ - "getrandom", + "getrandom 0.2.15", "once_cell", "version_check", ] @@ -191,6 +191,18 @@ dependencies = [ "wasi", ] +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "wasip2", +] + [[package]] name = "hashbrown" version = "0.12.3" @@ -287,7 +299,7 @@ dependencies = [ "num-cmp", "num-traits", "proptest", - "rand", + "rand 0.9.2", "rkyv", "schemars", "serde", @@ -324,8 +336,8 @@ dependencies = [ "bitflags", "lazy_static", "num-traits", - "rand", - "rand_chacha", + "rand 0.8.5", + "rand_chacha 0.3.1", "rand_xorshift", "regex-syntax", "rusty-fork", @@ -368,6 +380,12 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + [[package]] name = "radium" version = "0.7.0" @@ -381,8 +399,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha", - "rand_core", + "rand_chacha 0.3.1", + "rand_core 0.6.4", +] + +[[package]] +name = "rand" +version = "0.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6db2770f06117d490610c7488547d543617b21bfa07796d7a12f6f1bd53850d1" +dependencies = [ + "rand_chacha 0.9.0", + "rand_core 0.9.3", "serde", ] @@ -393,7 +421,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core", + "rand_core 0.6.4", +] + +[[package]] +name = "rand_chacha" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3022b5f1df60f26e1ffddd6c66e8aa15de382ae63b3a0c1bfc0e4d3e3f325cb" +dependencies = [ + "ppv-lite86", + "rand_core 0.9.3", ] [[package]] @@ -402,7 +440,16 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom", + "getrandom 0.2.15", +] + +[[package]] +name = "rand_core" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "99d9a13982dcf210057a8a78572b2217b667c3beacbf3a0d8b454f6f82837d38" +dependencies = [ + "getrandom 0.3.4", "serde", ] @@ -412,7 +459,7 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" dependencies = [ - "rand_core", + "rand_core 0.6.4", ] [[package]] @@ -668,6 +715,15 @@ version = "0.11.0+wasi-snapshot-preview1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" +[[package]] +name = "wasip2" +version = "1.0.1+wasi-0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" +dependencies = [ + "wit-bindgen", +] + [[package]] name = "windows-sys" version = "0.59.0" @@ -741,6 +797,12 @@ version = "0.52.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" +[[package]] +name = "wit-bindgen" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" + [[package]] name = "wyz" version = "0.5.1" diff --git a/Cargo.toml b/Cargo.toml index 61de11f..514fc78 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ derive-visitor = { version = "0.4.0", optional = true } num-cmp = { version = "0.1.0", optional = true } num-traits = { version = "0.2.9", default-features = false } proptest = { version = "1.0.0", optional = true } -rand = { version = "0.8.3", optional = true, default-features = false } +rand = { version = "0.9.2", optional = true, default-features = false } rkyv = { version = "0.7.41", optional = true, default-features = false, features = ["rend"] } schemars = { version = "0.8.8", optional = true } serde = { version = "1.0", optional = true, default-features = false } @@ -35,8 +35,8 @@ serde_test = "1.0" default = ["std"] std = ["num-traits/std"] libm = ["num-traits/libm"] -serde = ["dep:serde", "rand?/serde1"] -randtest = ["rand/std", "rand/std_rng"] +serde = ["dep:serde", "rand?/serde"] +randtest = ["rand/default"] rkyv = ["rkyv_32"] rkyv_16 = ["dep:rkyv", "rkyv?/size_16"] rkyv_32 = ["dep:rkyv", "rkyv?/size_32"] diff --git a/src/lib.rs b/src/lib.rs index 00d64a7..c6616e5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1243,7 +1243,7 @@ impl Num for OrderedFloat { not(feature = "bytemuck"), doc = "[`bytemuck`]: https://docs.rs/bytemuck/1/" )] -#[derive(PartialOrd, PartialEq, Default, Clone, Copy)] +#[derive(PartialEq, Default, Clone, Copy)] #[repr(transparent)] pub struct NotNan(T); @@ -1312,12 +1312,20 @@ impl Borrow for NotNan { } } -#[allow(clippy::derive_ord_xor_partial_ord)] +impl PartialOrd for NotNan { + #[inline] + fn partial_cmp(&self, other: &NotNan) -> Option { + Some(self.cmp(other)) + } +} + impl Ord for NotNan { + #[inline] fn cmp(&self, other: &NotNan) -> Ordering { // Can't use unreachable_unchecked because unsafe code can't depend on FloatCore impl. // https://github.com/reem/rust-ordered-float/issues/150 - self.partial_cmp(other) + self.0 + .partial_cmp(&other.0) .expect("partial_cmp failed for non-NaN value") } } @@ -2567,8 +2575,8 @@ mod impl_schemars { #[cfg(feature = "rand")] mod impl_rand { use super::{NotNan, OrderedFloat}; - use rand::distributions::uniform::*; - use rand::distributions::{Distribution, Open01, OpenClosed01, Standard}; + use rand::distr::uniform::*; + use rand::distr::{Distribution, Open01, OpenClosed01, StandardUniform}; use rand::Rng; macro_rules! impl_distribution { @@ -2592,7 +2600,7 @@ mod impl_rand { } } - impl_distribution! { Standard, f32, f64 } + impl_distribution! { StandardUniform, f32, f64 } impl_distribution! { Open01, f32, f64 } impl_distribution! { OpenClosed01, f32, f64 } @@ -2638,14 +2646,17 @@ mod impl_rand { ($f:ty) => { impl UniformSampler for UniformNotNan<$f> { type X = NotNan<$f>; - fn new(low: B1, high: B2) -> Self + fn new(low: B1, high: B2) -> Result where B1: SampleBorrow + Sized, B2: SampleBorrow + Sized, { - UniformNotNan(UniformFloat::<$f>::new(low.borrow().0, high.borrow().0)) + Ok(UniformNotNan(UniformFloat::<$f>::new( + low.borrow().0, + high.borrow().0, + )?)) } - fn new_inclusive(low: B1, high: B2) -> Self + fn new_inclusive(low: B1, high: B2) -> Result where B1: SampleBorrow + Sized, B2: SampleBorrow + Sized, @@ -2660,14 +2671,17 @@ mod impl_rand { impl UniformSampler for UniformOrdered<$f> { type X = OrderedFloat<$f>; - fn new(low: B1, high: B2) -> Self + fn new(low: B1, high: B2) -> Result where B1: SampleBorrow + Sized, B2: SampleBorrow + Sized, { - UniformOrdered(UniformFloat::<$f>::new(low.borrow().0, high.borrow().0)) + Ok(UniformOrdered(UniformFloat::<$f>::new( + low.borrow().0, + high.borrow().0, + )?)) } - fn new_inclusive(low: B1, high: B2) -> Self + fn new_inclusive(low: B1, high: B2) -> Result where B1: SampleBorrow + Sized, B2: SampleBorrow + Sized, @@ -2690,19 +2704,19 @@ mod impl_rand { fn sample_fuzz() where - Standard: Distribution>, + StandardUniform: Distribution>, Open01: Distribution>, OpenClosed01: Distribution>, - Standard: Distribution>, + StandardUniform: Distribution>, Open01: Distribution>, OpenClosed01: Distribution>, T: crate::Float, { - let mut rng = rand::thread_rng(); - let f1: NotNan = rng.sample(Standard); + let mut rng = rand::rng(); + let f1: NotNan = rng.sample(StandardUniform); let f2: NotNan = rng.sample(Open01); let f3: NotNan = rng.sample(OpenClosed01); - let _: OrderedFloat = rng.sample(Standard); + let _: OrderedFloat = rng.sample(StandardUniform); let _: OrderedFloat = rng.sample(Open01); let _: OrderedFloat = rng.sample(OpenClosed01); assert!(!f1.into_inner().is_nan()); @@ -2727,24 +2741,24 @@ mod impl_rand { NotNan::new(0f64).unwrap(), NotNan::new(f64::INFINITY).unwrap(), ); - let uniform = Uniform::new(low, high); - let _ = uniform.sample(&mut rand::thread_rng()); + let uniform = Uniform::new(low, high).unwrap(); + let _ = uniform.sample(&mut rand::rng()); } #[test] #[should_panic] fn uniform_sampling_panic_on_infinity_ordered() { let (low, high) = (OrderedFloat(0f64), OrderedFloat(f64::INFINITY)); - let uniform = Uniform::new(low, high); - let _ = uniform.sample(&mut rand::thread_rng()); + let uniform = Uniform::new(low, high).unwrap(); + let _ = uniform.sample(&mut rand::rng()); } #[test] #[should_panic] fn uniform_sampling_panic_on_nan_ordered() { let (low, high) = (OrderedFloat(0f64), OrderedFloat(f64::NAN)); - let uniform = Uniform::new(low, high); - let _ = uniform.sample(&mut rand::thread_rng()); + let uniform = Uniform::new(low, high).unwrap(); + let _ = uniform.sample(&mut rand::rng()); } } }