From b05f994e38a7d77b3c069a8bf6281ec36f6d2d8a Mon Sep 17 00:00:00 2001 From: chxry Date: Wed, 2 Oct 2024 22:52:29 +0100 Subject: [PATCH] Fix no_std compiles --- Cargo.toml | 2 +- src/config/hashing.rs | 6 +++++- src/lib.rs | 4 ++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f3c1aaba2..8add432f4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,7 +22,7 @@ smallvec = { version = "1.7.0", default-features = false, features = ["union", " thin-vec = { version = "0.2.13", default-features = false } ahash = { version = "0.8.2", default-features = false, features = ["compile-time-rng"] } num-traits = { version = "0.2.0", default-features = false } -once_cell = { version = "1.19.0", default-features = false, features = ["critical-section"] } +once_cell = { version = "1.20.1", default-features = false, features = ["race", "portable-atomic", "alloc"] } bitflags = { version = "2.0.0", default-features = false } smartstring = { version = "1.0.0", default-features = false } rhai_codegen = { version = "2.1.0", path = "codegen" } diff --git a/src/config/hashing.rs b/src/config/hashing.rs index e6dcee9ae..cf7fcda5f 100644 --- a/src/config/hashing.rs +++ b/src/config/hashing.rs @@ -54,7 +54,11 @@ pub use crate::api::deprecated::config::hashing::{get_ahash_seed, set_ahash_seed /// ``` #[inline(always)] pub fn set_hashing_seed(new_seed: Option<[u64; 4]>) -> Result<(), Option<[u64; 4]>> { - HASHING_SEED.set(new_seed) + #[cfg(feature = "std")] + return HASHING_SEED.set(new_seed); + + #[cfg(not(feature = "std"))] + return HASHING_SEED.set(new_seed.into()).map_err(|err| *err); } /// Get the current hashing Seed. diff --git a/src/lib.rs b/src/lib.rs index f385c701a..d02314fad 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -220,8 +220,12 @@ type ExclusiveRange = std::ops::Range; /// An inclusive integer range. type InclusiveRange = std::ops::RangeInclusive; +#[cfg(feature = "std")] use once_cell::sync::OnceCell; +#[cfg(not(feature = "std"))] +use once_cell::race::OnceBox as OnceCell; + pub use api::build_type::{CustomType, TypeBuilder}; #[cfg(not(feature = "no_custom_syntax"))] pub use api::custom_syntax::Expression;