diff --git a/src/fn_builtin.rs b/src/fn_builtin.rs index 7d4f9c04..3fdf9a42 100644 --- a/src/fn_builtin.rs +++ b/src/fn_builtin.rs @@ -118,6 +118,13 @@ pub fn get_builtin_binary_op_fn( $func(x, y) }) }; + ($base:ty => $op:tt) => { + return Some(|_, args| { + let x = &*args[0].read_lock::<$base>().unwrap(); + let y = &*args[1].read_lock::<$base>().unwrap(); + Ok((x $op y).into()) + }) + }; } macro_rules! impl_float { @@ -327,26 +334,14 @@ pub fn get_builtin_binary_op_fn( if type1 == TypeId::of::() { match op { - "+" => { - return Some(|_, args| { - let x = &*args[0].read_lock::().unwrap(); - let y = &*args[1].read_lock::().unwrap(); - Ok((x + y).into()) - }) - } - "-" => { - return Some(|_, args| { - let x = &*args[0].read_lock::().unwrap(); - let y = &*args[1].read_lock::().unwrap(); - Ok((x - y).into()) - }) - } - "==" => impl_op!(&str => as_str == as_str), - "!=" => impl_op!(&str => as_str != as_str), - ">" => impl_op!(&str => as_str > as_str), - ">=" => impl_op!(&str => as_str >= as_str), - "<" => impl_op!(&str => as_str < as_str), - "<=" => impl_op!(&str => as_str <= as_str), + "+" => impl_op!(ImmutableString => +), + "-" => impl_op!(ImmutableString => -), + "==" => impl_op!(ImmutableString => ==), + "!=" => impl_op!(ImmutableString => !=), + ">" => impl_op!(ImmutableString => >), + ">=" => impl_op!(ImmutableString => >=), + "<" => impl_op!(ImmutableString => <), + "<=" => impl_op!(ImmutableString => <=), _ => return None, } }