diff --git a/.ci/build.sh b/.ci/build.sh index 20c75afa..fb0e7e04 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -5,9 +5,7 @@ set -ex cargo build --verbose cargo test --verbose -if [ "$TRAVIS_RUST_VERSION" = "nightly" ] -then +if [[ $TRAVIS_RUST_VERSION == "nightly" ]]; then cargo build --verbose --features no_std cargo test --verbose --features no_std fi - diff --git a/src/any.rs b/src/any.rs index 7f637187..202afa24 100644 --- a/src/any.rs +++ b/src/any.rs @@ -30,12 +30,24 @@ use crate::stdlib::time::Instant; #[cfg(target_arch = "wasm32")] use instant::Instant; +mod private { + use crate::fn_native::SendSync; + use crate::stdlib::any::Any; + + /// A sealed trait that prevents other crates from implementing [Variant]. + /// + /// [Variant]: super::Variant + pub trait Sealed {} + + impl Sealed for T {} +} + /// Trait to represent any type. /// /// Currently, `Variant` is not `Send` nor `Sync`, so it can practically be any type. /// Turn on the `sync` feature to restrict it to only types that implement `Send + Sync`. #[cfg(not(feature = "sync"))] -pub trait Variant: Any { +pub trait Variant: Any + private::Sealed { /// Convert this `Variant` trait object to `&dyn Any`. fn as_any(&self) -> &dyn Any; @@ -53,10 +65,6 @@ pub trait Variant: Any { /// Clone into `Dynamic`. fn clone_into_dynamic(&self) -> Dynamic; - - /// This trait may only be implemented by `rhai`. - #[doc(hidden)] - fn _closed(&self) -> _Private; } /// Trait to represent any type. @@ -64,7 +72,7 @@ pub trait Variant: Any { /// `From<_>` is implemented for `i64` (`i32` if `only_i32`), `f64` (if not `no_float`), /// `bool`, `String`, `char`, `Vec` (into `Array`) and `HashMap` (into `Map`). #[cfg(feature = "sync")] -pub trait Variant: Any + Send + Sync { +pub trait Variant: Any + Send + Sync + private::Sealed { /// Convert this `Variant` trait object to `&dyn Any`. fn as_any(&self) -> &dyn Any; @@ -82,10 +90,6 @@ pub trait Variant: Any + Send + Sync { /// Clone into `Dynamic`. fn clone_into_dynamic(&self) -> Dynamic; - - /// This trait may only be implemented by `rhai`. - #[doc(hidden)] - fn _closed(&self) -> _Private; } impl Variant for T { @@ -107,9 +111,6 @@ impl Variant for T { fn clone_into_dynamic(&self) -> Dynamic { Dynamic::from(self.clone()) } - fn _closed(&self) -> _Private { - _Private - } } impl dyn Variant { diff --git a/src/engine.rs b/src/engine.rs index cb0a3000..cd87cc1e 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1063,7 +1063,7 @@ impl Engine { #[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_index"))] _ => { - let type_name = self.map_type_name(val.type_name()); + let type_name = val.type_name(); let args = &mut [val, &mut idx]; self.exec_fn_call( state, lib, FN_IDX_GET, true, 0, args, is_ref, true, None, level,