rbatis_codegen/
ops_mul.rs1use crate::ops::{AsProxy, Mul};
2use crate::ops_macros::{impl_numeric_binary_op, impl_same_type_binary_op, impl_value_binary_op};
3use rbs::Value;
4
5fn op_mul_value(left: Value, rhs: Value) -> Value {
6 match left {
7 Value::I32(s) => Value::I32(s * rhs.i32()),
8 Value::I64(s) => Value::I64(s * rhs.i64()),
9 Value::U32(s) => Value::U32(s * rhs.u32()),
10 Value::U64(s) => Value::U64(s * rhs.u64()),
11 Value::F32(s) => Value::F32(s * rhs.f64() as f32),
12 Value::F64(s) => Value::F64(s * rhs.f64()),
13 Value::Ext(_, e) => op_mul_value(*e, rhs),
14 _ => Value::Null,
15 }
16}
17
18fn op_mul_u64(value: &Value, other: u64) -> u64 {
19 value.u64() * other
20}
21
22fn op_mul_i64(value: &Value, other: i64) -> i64 {
23 value.i64() * other
24}
25
26fn op_mul_f64(value: &Value, other: f64) -> f64 {
27 value.f64() * other
28}
29
30impl_value_binary_op!(Mul, op_mul, op_mul_value);
31impl_numeric_binary_op!(
32 Mul,
33 op_mul,
34 op_mul_u64,
35 op_mul_u64,
36 [u8, u16, u32, u64],
37 u64
38);
39impl_numeric_binary_op!(
40 Mul,
41 op_mul,
42 op_mul_i64,
43 op_mul_i64,
44 [i8, i16, i32, i64, isize, usize],
45 i64
46);
47impl_numeric_binary_op!(Mul, op_mul, op_mul_f64, op_mul_f64, [f32, f64], f64);
48impl_same_type_binary_op!(
49 Mul,
50 op_mul,
51 *,
52 [
53 u8, u16, u32, u64, i8, i16, i32, i64, isize, usize, f32, f64
54 ]
55);
56
57#[cfg(test)]
58mod test {
59 use crate::ops::Mul;
60 use rbs::Value;
61
62 #[test]
63 fn test_mul() {
64 let value = Value::I32(3);
65 assert_eq!((&value).op_mul(&4i64), 12i64);
66 assert_eq!(value.op_mul(4i64), 12i64);
67 assert_eq!(Value::I32(3).op_mul(&&Value::I32(4)), Value::I32(12));
68 }
69}