From 2ed59a39d969a7066a2d92e5bb2ea29993e95880 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gon=C3=A7alo=20Rica=20Pais=20da=20Silva?= Date: Sat, 24 Feb 2024 15:28:38 +0100 Subject: [PATCH] fix: no-std feature housekeeping --- src/internal/state.rs | 5 ++++- src/lib.rs | 6 +++--- src/rng.rs | 5 ++++- src/source/wyrand.rs | 5 ++++- src/traits.rs | 4 ++-- tests/smoke/mod.rs | 2 ++ tests/suite.rs | 2 +- 7 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/internal/state.rs b/src/internal/state.rs index 0858072..9d2bd36 100644 --- a/src/internal/state.rs +++ b/src/internal/state.rs @@ -221,9 +221,12 @@ mod tests { assert_eq!(state.get(), 11); } - #[cfg(feature = "fmt")] + #[cfg(all(feature = "fmt", feature = "alloc"))] #[test] fn cell_state_no_leaking_debug() { + #[cfg(all(feature = "alloc", not(feature = "std")))] + use alloc::format; + let state = CellState::with_seed(Default::default()); assert_eq!(format!("{state:?}"), "CellState"); diff --git a/src/lib.rs b/src/lib.rs index b391fa5..ffc1ad0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -10,7 +10,7 @@ //! //! Generate a random value: //! -//! ``` +//! ```ignore //! use turborand::prelude::*; //! //! let rand = Rng::new(); @@ -20,7 +20,7 @@ //! //! Sample a value from a list: //! -//! ``` +//! ```ignore //! use turborand::prelude::*; //! //! let rand = Rng::new(); @@ -32,7 +32,7 @@ //! //! Generate a vector with random values: //! -//! ``` +//! ```ignore //! use turborand::prelude::*; //! use std::iter::repeat_with; //! diff --git a/src/rng.rs b/src/rng.rs index afd3079..77325d0 100644 --- a/src/rng.rs +++ b/src/rng.rs @@ -227,9 +227,12 @@ mod tests { use super::*; - #[cfg(feature = "fmt")] + #[cfg(all(feature = "fmt", feature = "alloc"))] #[test] fn rng_no_leaking_debug() { + #[cfg(all(feature = "alloc", not(feature = "std")))] + use alloc::format; + let rng = Rng::with_seed(Default::default()); assert_eq!(format!("{rng:?}"), "Rng(WyRand(CellState))"); diff --git a/src/source/wyrand.rs b/src/source/wyrand.rs index ebf00e5..06706d7 100644 --- a/src/source/wyrand.rs +++ b/src/source/wyrand.rs @@ -142,9 +142,12 @@ mod tests { ); } - #[cfg(feature = "fmt")] + #[cfg(all(feature = "fmt", feature = "alloc"))] #[test] fn no_leaking_debug() { + #[cfg(all(feature = "alloc", not(feature = "std")))] + use alloc::format; + let rng = WyRand::::with_seed(Default::default()); assert_eq!(format!("{rng:?}"), "WyRand(CellState)"); diff --git a/src/traits.rs b/src/traits.rs index 4cc65fc..cde58a3 100644 --- a/src/traits.rs +++ b/src/traits.rs @@ -1,6 +1,6 @@ use core::ops::{Bound, RangeBounds}; -#[cfg(feature = "alloc")] +#[cfg(all(feature = "alloc", not(feature = "std")))] use alloc::{boxed::Box, vec::Vec}; use crate::internal::uniform::IncreasingUniformIter; @@ -1047,7 +1047,7 @@ mod tests { const GEN_KIND: TurboKind = TurboKind::FAST; fn gen(&self) -> [u8; SIZE] { - std::array::from_fn(|_| self.next()) + core::array::from_fn(|_| self.next()) } } diff --git a/tests/smoke/mod.rs b/tests/smoke/mod.rs index b0c62c4..352df13 100644 --- a/tests/smoke/mod.rs +++ b/tests/smoke/mod.rs @@ -285,6 +285,8 @@ fn small_range_smoke_testing() { #[test] #[cfg_attr(target_arch = "wasm32", wasm_bindgen_test)] fn unbounded_range_smoke_testing() { + use std::ops::RangeBounds; + let rng = Rng::default(); for _ in 0..1000 { diff --git a/tests/suite.rs b/tests/suite.rs index 82d206e..3297bfc 100644 --- a/tests/suite.rs +++ b/tests/suite.rs @@ -1,4 +1,4 @@ -use std::{iter::repeat_with, ops::RangeBounds}; +use std::iter::repeat_with; use std::collections::BTreeMap;