diff --git a/src/func/builtin.rs b/src/func/builtin.rs index a257e2fd..aad1f1d7 100644 --- a/src/func/builtin.rs +++ b/src/func/builtin.rs @@ -250,7 +250,7 @@ pub fn get_builtin_binary_op_fn( OP_CONTAINS => Some(|_, args| { let s = &*args[0].read_lock::().expect(BUILTIN); let c = args[1].as_char().expect(BUILTIN); - Ok((s.contains(c)).into()) + Ok(s.contains(c).into()) }), _ => None, }; @@ -306,6 +306,16 @@ pub fn get_builtin_binary_op_fn( // Handle ranges here because ranges are implemented as custom type if type1 == TypeId::of::() { + if type2 == TypeId::of::() { + return match op { + OP_CONTAINS => Some(|_, args| { + let range = &*args[0].read_lock::().expect(BUILTIN); + let x = args[1].as_int().expect("`INT`"); + Ok(range.contains(&x).into()) + }), + _ => None, + }; + } if type1 == type2 { return match op { "==" => Some(impl_op!(ExclusiveRange == ExclusiveRange)), @@ -316,6 +326,16 @@ pub fn get_builtin_binary_op_fn( } if type1 == TypeId::of::() { + if type2 == TypeId::of::() { + return match op { + OP_CONTAINS => Some(|_, args| { + let range = &*args[0].read_lock::().expect(BUILTIN); + let x = args[1].as_int().expect("`INT`"); + Ok(range.contains(&x).into()) + }), + _ => None, + }; + } if type1 == type2 { return match op { "==" => Some(impl_op!(InclusiveRange == InclusiveRange)), @@ -433,11 +453,7 @@ pub fn get_builtin_binary_op_fn( ">=" => Some(impl_op!(ImmutableString >= ImmutableString)), "<" => Some(impl_op!(ImmutableString < ImmutableString)), "<=" => Some(impl_op!(ImmutableString <= ImmutableString)), - OP_CONTAINS => Some(|_, args| { - let s1 = &*args[0].read_lock::().expect(BUILTIN); - let s2 = &*args[1].read_lock::().expect(BUILTIN); - Ok((s1.contains(s2.as_str())).into()) - }), + OP_CONTAINS => Some(impl_op!(ImmutableString.contains(ImmutableString.as_str()))), _ => None, }; } diff --git a/src/packages/iter_basic.rs b/src/packages/iter_basic.rs index 36268851..86952e05 100644 --- a/src/packages/iter_basic.rs +++ b/src/packages/iter_basic.rs @@ -537,10 +537,6 @@ mod range_functions { pub fn end(range: &mut ExclusiveRange) -> INT { range.end } - #[rhai_fn(name = "contains", pure)] - pub fn contains(range: &mut ExclusiveRange, value: INT) -> bool { - range.contains(&value) - } #[rhai_fn(get = "is_inclusive", name = "is_inclusive", pure)] pub fn is_inclusive(range: &mut ExclusiveRange) -> bool { let _range = range; @@ -559,10 +555,6 @@ mod range_functions { pub fn end_inclusive(range: &mut InclusiveRange) -> INT { *range.end() } - #[rhai_fn(name = "contains", pure)] - pub fn contains_inclusive(range: &mut InclusiveRange, value: INT) -> bool { - range.contains(&value) - } #[rhai_fn(get = "is_inclusive", name = "is_inclusive", pure)] pub fn is_inclusive_inclusive(range: &mut InclusiveRange) -> bool { let _range = range;