This commit is contained in:
Stephen Chung 2020-07-25 15:58:37 +08:00
commit 6a96be3382
3 changed files with 16 additions and 17 deletions

View File

@ -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

View File

@ -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<T: Any + Clone + SendSync> 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<T>` (into `Array`) and `HashMap<String, T>` (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<T: Any + Clone + SendSync> Variant for T {
@ -107,9 +111,6 @@ impl<T: Any + Clone + SendSync> Variant for T {
fn clone_into_dynamic(&self) -> Dynamic {
Dynamic::from(self.clone())
}
fn _closed(&self) -> _Private {
_Private
}
}
impl dyn Variant {

View File

@ -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,