From 4adc044c79e548965d72ea3c9233cd762397d0a7 Mon Sep 17 00:00:00 2001 From: Stephen Chung Date: Sun, 4 Jul 2021 16:51:05 +0800 Subject: [PATCH] Fix builds. --- src/dynamic.rs | 80 +++++++++++++++++++----------------- src/engine.rs | 1 + src/packages/string_basic.rs | 4 ++ 3 files changed, 48 insertions(+), 37 deletions(-) diff --git a/src/dynamic.rs b/src/dynamic.rs index 22c66a8a..d4c0732e 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -508,6 +508,8 @@ impl Hash for Dynamic { Union::Int(ref i, _, _) => i.hash(state), #[cfg(not(feature = "no_float"))] Union::Float(ref f, _, _) => f.hash(state), + #[cfg(feature = "decimal")] + Union::Decimal(ref d, _, _) => d.hash(state), #[cfg(not(feature = "no_index"))] Union::Array(ref a, _, _) => a.as_ref().hash(state), #[cfg(not(feature = "no_object"))] @@ -522,46 +524,50 @@ impl Hash for Dynamic { #[cfg(feature = "sync")] Union::Shared(ref cell, _, _) => (*cell.read().unwrap()).hash(state), - #[cfg(not(feature = "only_i32"))] - #[cfg(not(feature = "only_i64"))] - Union::Variant(ref value, _, _) => { - let value_any = (***value).as_any(); - let type_id = value_any.type_id(); + Union::Variant(ref _value, _, _) => { + #[cfg(not(feature = "only_i32"))] + #[cfg(not(feature = "only_i64"))] + { + let value_any = (***_value).as_any(); + let type_id = value_any.type_id(); - if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); - } else if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); - } else if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); - } else if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); - } else if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); - } else if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); - } else if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); - } else if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); + if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } else if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } else if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } else if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } else if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } else if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } else if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } else if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } + + #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] + if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } else if type_id == TypeId::of::() { + TypeId::of::().hash(state); + value_any.downcast_ref::().expect(CHECKED).hash(state); + } } - #[cfg(not(any(target_arch = "wasm32", target_arch = "wasm64")))] - if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); - } else if type_id == TypeId::of::() { - TypeId::of::().hash(state); - value_any.downcast_ref::().expect(CHECKED).hash(state); - } + unimplemented!("a custom type cannot be hashed") } #[cfg(not(feature = "no_std"))] diff --git a/src/engine.rs b/src/engine.rs index 66f825e2..91b20d8b 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -669,6 +669,7 @@ impl EvalState { scope_level: 0, operations: 0, modules: 0, + #[cfg(not(feature = "no_module"))] resolver: None, fn_resolution_caches: Vec::new(), } diff --git a/src/packages/string_basic.rs b/src/packages/string_basic.rs index 348e602c..c361863f 100644 --- a/src/packages/string_basic.rs +++ b/src/packages/string_basic.rs @@ -173,6 +173,10 @@ mod number_formatting { pub fn int_to_octal(value: INT) -> ImmutableString { to_octal(value) } + #[rhai_fn(name = "to_binary")] + pub fn int_to_binary(value: INT) -> ImmutableString { + to_binary(value) + } #[cfg(not(feature = "only_i32"))] #[cfg(not(feature = "only_i64"))]