diff --git a/src/ast.rs b/src/ast.rs index 9af2bdf2..ca012df1 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -1548,7 +1548,7 @@ pub enum Expr { Array(Box>, Position), /// #{ name:expr, ... } Map( - Box<(StaticVec<(Ident, Expr)>, BTreeMap)>, + Box<(StaticVec<(Ident, Expr)>, BTreeMap)>, Position, ), /// () diff --git a/src/dynamic.rs b/src/dynamic.rs index 1ec4d82c..fd730ef3 100644 --- a/src/dynamic.rs +++ b/src/dynamic.rs @@ -1712,7 +1712,7 @@ impl crate::stdlib::iter::FromIterator for Dynamic { } #[cfg(not(feature = "no_object"))] #[cfg(not(feature = "no_std"))] -impl, T: Variant + Clone> From> +impl, T: Variant + Clone> From> for Dynamic { #[inline(always)] @@ -1729,8 +1729,8 @@ impl, T: Variant + Clone> From, T: Variant + Clone> From> - for Dynamic +impl, T: Variant + Clone> + From> for Dynamic { #[inline(always)] fn from(value: crate::stdlib::collections::BTreeMap) -> Self { diff --git a/src/engine.rs b/src/engine.rs index e8255c63..16f32037 100644 --- a/src/engine.rs +++ b/src/engine.rs @@ -1573,12 +1573,12 @@ impl Engine { self.make_type_mismatch_err::(idx.type_name(), idx_pos) })?; - if _create && !map.contains_key(index) { - map.insert(index.clone(), Default::default()); + if _create && !map.contains_key(index.as_str()) { + map.insert(index.clone().into(), Default::default()); } Ok(map - .get_mut(index) + .get_mut(index.as_str()) .map(Target::from) .unwrap_or_else(|| Target::from(()))) } diff --git a/src/fn_builtin.rs b/src/fn_builtin.rs index 3558d098..515c6a68 100644 --- a/src/fn_builtin.rs +++ b/src/fn_builtin.rs @@ -85,6 +85,13 @@ pub fn get_builtin_binary_op_fn( Ok(x.$func(y).into()) }) }; + ($xx:ident . $func:ident ( $yy:ident . $yyy:ident () )) => { + return Some(|_, args| { + let x = &*args[0].read_lock::<$xx>().unwrap(); + let y = &*args[1].read_lock::<$yy>().unwrap(); + Ok(x.$func(y.$yyy()).into()) + }) + }; ($func:ident ( $op:tt )) => { return Some(|_, args| { let (x, y) = $func(args); @@ -284,7 +291,7 @@ pub fn get_builtin_binary_op_fn( use crate::Map; match op { - OP_CONTAINS => impl_op!(Map.contains_key(ImmutableString)), + OP_CONTAINS => impl_op!(Map.contains_key(ImmutableString.as_str())), _ => return None, } } diff --git a/src/lib.rs b/src/lib.rs index ae7785ea..146a3717 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -189,7 +189,7 @@ pub type Array = stdlib::vec::Vec; /// /// Not available under `no_object`. #[cfg(not(feature = "no_object"))] -pub type Map = stdlib::collections::BTreeMap; +pub type Map = stdlib::collections::BTreeMap; #[cfg(not(feature = "no_module"))] pub use module::ModuleResolver; diff --git a/src/packages/map_basic.rs b/src/packages/map_basic.rs index 41212ec0..d76dbcb7 100644 --- a/src/packages/map_basic.rs +++ b/src/packages/map_basic.rs @@ -15,7 +15,7 @@ def_package!(crate:BasicMapPackage:"Basic object map utilities.", lib, { mod map_functions { #[rhai_fn(name = "has", pure)] pub fn contains(map: &mut Map, prop: ImmutableString) -> bool { - map.contains_key(&prop) + map.contains_key(prop.as_str()) } #[rhai_fn(pure)] pub fn len(map: &mut Map) -> INT { @@ -25,7 +25,7 @@ mod map_functions { map.clear(); } pub fn remove(map: &mut Map, name: ImmutableString) -> Dynamic { - map.remove(&name).unwrap_or_else(|| ().into()) + map.remove(name.as_str()).unwrap_or_else(|| ().into()) } #[rhai_fn(name = "mixin", name = "+=")] pub fn mixin(map: &mut Map, map2: Map) { diff --git a/src/parser.rs b/src/parser.rs index 810aba4c..083bd996 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -24,8 +24,8 @@ use crate::syntax::{CustomSyntax, MARKER_BLOCK, MARKER_EXPR, MARKER_IDENT}; use crate::token::{is_keyword_function, is_valid_identifier, Token, TokenStream}; use crate::utils::{get_hasher, IdentifierBuilder}; use crate::{ - calc_fn_hash, Dynamic, Engine, Identifier, ImmutableString, LexError, ParseError, - ParseErrorType, Position, Scope, Shared, StaticVec, AST, + calc_fn_hash, Dynamic, Engine, Identifier, LexError, ParseError, ParseErrorType, Position, + Scope, Shared, StaticVec, AST, }; #[cfg(not(feature = "no_float"))] @@ -685,7 +685,7 @@ fn parse_map_literal( settings.pos = eat_token(input, Token::MapStart); let mut map: StaticVec<(Ident, Expr)> = Default::default(); - let mut template: BTreeMap = Default::default(); + let mut template: BTreeMap = Default::default(); loop { const MISSING_RBRACE: &str = "to end this object map literal";