diff --git a/src/seq/index.rs b/src/seq/index.rs index 5e76af19..6a226418 100644 --- a/src/seq/index.rs +++ b/src/seq/index.rs @@ -295,14 +295,14 @@ where key: f64, } impl PartialOrd for Element { - fn partial_cmp(&self, other: &Self) -> Option { + fn partial_cmp(&self, other: &Self) -> Option { self.key .partial_cmp(&other.key) - .or(Some(std::cmp::Ordering::Less)) + .or(Some(core::cmp::Ordering::Less)) } } impl Ord for Element { - fn cmp(&self, other: &Self) -> std::cmp::Ordering { + fn cmp(&self, other: &Self) -> core::cmp::Ordering { self.partial_cmp(other).unwrap() // partial_cmp will always produce a value } } @@ -346,6 +346,9 @@ where #[cfg(not(feature = "partition_at_index"))] { + #[cfg(all(feature = "alloc", not(feature = "std")))] + use crate::alloc::collections::BinaryHeap; + #[cfg(feature = "std")] use std::collections::BinaryHeap; // Partially sort the array such that the `amount` elements with the largest diff --git a/src/seq/mod.rs b/src/seq/mod.rs index f9407f8e..bdaa19a3 100644 --- a/src/seq/mod.rs +++ b/src/seq/mod.rs @@ -1062,14 +1062,14 @@ mod test { assert_eq!(result.len(), 0); // Case 5: NaN weights - let choices = [('a', std::f64::NAN), ('b', 1.0), ('c', 1.0)]; + let choices = [('a', core::f64::NAN), ('b', 1.0), ('c', 1.0)]; assert!(matches!( choices.choose_multiple_weighted(&mut rng, 2, |item| item.1), Err(WeightedError::InvalidWeight) )); // Case 6: +infinity weights - let choices = [('a', std::f64::INFINITY), ('b', 1.0), ('c', 1.0)]; + let choices = [('a', core::f64::INFINITY), ('b', 1.0), ('c', 1.0)]; for _ in 0..100 { let result = choices .choose_multiple_weighted(&mut rng, 2, |item| item.1) @@ -1080,7 +1080,7 @@ mod test { } // Case 7: -infinity weights - let choices = [('a', std::f64::NEG_INFINITY), ('b', 1.0), ('c', 1.0)]; + let choices = [('a', core::f64::NEG_INFINITY), ('b', 1.0), ('c', 1.0)]; assert!(matches!( choices.choose_multiple_weighted(&mut rng, 2, |item| item.1), Err(WeightedError::InvalidWeight)