mybatis_sql/
ops_mul.rs

1use crate::ops::AsProxy;
2use crate::ops::Mul;
3use crate::ops::Value;
4
5impl Mul<&Value> for Value {
6    type Output = Value;
7    fn op_mul(self, rhs: &Value) -> Self::Output {
8        match self {
9            Value::Int32(s) => {
10                let rhs = rhs.i32();
11                return Value::Int32(s * rhs);
12            }
13            Value::Int64(s) => {
14                let rhs = rhs.i64();
15                return Value::Int64(s * rhs);
16            }
17            Value::UInt32(s) => {
18                let rhs = rhs.u32();
19                return Value::UInt32(s * rhs);
20            }
21            Value::UInt64(s) => {
22                let rhs = rhs.u64();
23                return Value::UInt64(s * rhs);
24            }
25            Value::Double(s) => {
26                let rhs = rhs.as_f64().unwrap_or_default();
27                return Value::Double(s * rhs);
28            }
29            _ => {
30                return Value::Null;
31            }
32        };
33    }
34}
35
36impl Mul<&&Value> for Value {
37    type Output = Value;
38    fn op_mul(self, rhs: &&Value) -> Self::Output {
39        match self {
40            Value::Int32(s) => {
41                let rhs = rhs.i32();
42                return Value::Int32(s * rhs);
43            }
44            Value::Int64(s) => {
45                let rhs = rhs.i64();
46                return Value::Int64(s * rhs);
47            }
48            Value::UInt32(s) => {
49                let rhs = rhs.u32();
50                return Value::UInt32(s * rhs);
51            }
52            Value::UInt64(s) => {
53                let rhs = rhs.u64();
54                return Value::UInt64(s * rhs);
55            }
56            Value::Double(s) => {
57                let rhs = rhs.as_f64().unwrap_or_default();
58                return Value::Double(s * rhs);
59            }
60            _ => {
61                return Value::Null;
62            }
63        };
64    }
65}
66
67impl Mul<Value> for Value {
68    type Output = Value;
69    fn op_mul(self, rhs: Value) -> Self::Output {
70        match self {
71            Value::Int32(s) => {
72                let rhs = rhs.i32();
73                return Value::Int32(s * rhs);
74            }
75            Value::Int64(s) => {
76                let rhs = rhs.i64();
77                return Value::Int64(s * rhs);
78            }
79            Value::UInt32(s) => {
80                let rhs = rhs.u32();
81                return Value::UInt32(s * rhs);
82            }
83            Value::UInt64(s) => {
84                let rhs = rhs.u64();
85                return Value::UInt64(s * rhs);
86            }
87            Value::Double(s) => {
88                let rhs = rhs.as_f64().unwrap_or_default();
89                return Value::Double(s * rhs);
90            }
91            _ => {
92                return Value::Null;
93            }
94        };
95    }
96}
97
98impl Mul<&Value> for &Value {
99    type Output = Value;
100    fn op_mul(self, rhs: &Value) -> Self::Output {
101        match self {
102            Value::Int32(s) => {
103                let rhs = rhs.i32();
104                return Value::Int32(s * rhs);
105            }
106            Value::Int64(s) => {
107                let rhs = rhs.i64();
108                return Value::Int64(s * rhs);
109            }
110            Value::UInt32(s) => {
111                let rhs = rhs.u32();
112                return Value::UInt32(s * rhs);
113            }
114            Value::UInt64(s) => {
115                let rhs = rhs.u64();
116                return Value::UInt64(s * rhs);
117            }
118            Value::Double(s) => {
119                let rhs = rhs.as_f64().unwrap_or_default();
120                return Value::Double(s * rhs);
121            }
122            _ => {
123                return Value::Null;
124            }
125        };
126    }
127}
128
129impl Mul<&&Value> for &Value {
130    type Output = Value;
131    fn op_mul(self, rhs: &&Value) -> Self::Output {
132        match self {
133            Value::Int32(s) => {
134                let rhs = rhs.i32();
135                return Value::Int32(s * rhs);
136            }
137            Value::Int64(s) => {
138                let rhs = rhs.i64();
139                return Value::Int64(s * rhs);
140            }
141            Value::UInt32(s) => {
142                let rhs = rhs.u32();
143                return Value::UInt32(s * rhs);
144            }
145            Value::UInt64(s) => {
146                let rhs = rhs.u64();
147                return Value::UInt64(s * rhs);
148            }
149            Value::Double(s) => {
150                let rhs = rhs.as_f64().unwrap_or_default();
151                return Value::Double(s * rhs);
152            }
153            _ => {
154                return Value::Null;
155            }
156        };
157    }
158}
159
160impl Mul<Value> for &Value {
161    type Output = Value;
162    fn op_mul(self, rhs: Value) -> Self::Output {
163        match self {
164            Value::Int32(s) => {
165                let rhs = rhs.i32();
166                return Value::Int32(s * rhs);
167            }
168            Value::Int64(s) => {
169                let rhs = rhs.i64();
170                return Value::Int64(s * rhs);
171            }
172            Value::UInt32(s) => {
173                let rhs = rhs.u32();
174                return Value::UInt32(s * rhs);
175            }
176            Value::UInt64(s) => {
177                let rhs = rhs.u64();
178                return Value::UInt64(s * rhs);
179            }
180            Value::Double(s) => {
181                let rhs = rhs.as_f64().unwrap_or_default();
182                return Value::Double(s * rhs);
183            }
184            _ => {
185                return Value::Null;
186            }
187        };
188    }
189}
190
191fn op_mul_u32(value: &Value, other: u32) -> u32 {
192    value.u32() * other
193}
194
195fn op_mul_u64(value: &Value, other: u64) -> u64 {
196    value.u64() * other
197}
198
199fn op_mul_i32(value: &Value, other: i32) -> i32 {
200    value.i32() * other
201}
202
203fn op_mul_i64(value: &Value, other: i64) -> i64 {
204    value.i64() * other
205}
206
207fn op_mul_f64(value: &Value, other: f64) -> f64 {
208    value.f64() * other
209}
210
211macro_rules! impl_numeric_mul {
212    ($($mul:ident [$($ty:ty)*]-> $return_ty:ty)*) => {
213        $($(
214            impl Mul<$ty> for Value {
215                type Output = $return_ty;
216                fn op_mul(self, other: $ty) -> Self::Output {
217                    $mul(&self, other as _)
218                }
219            }
220
221            impl Mul<Value> for $ty {
222                type Output = $return_ty;
223                fn op_mul(self, other: Value) -> Self::Output {
224                    $mul(&other, self as _)
225                }
226            }
227
228            impl Mul<&Value> for $ty {
229                type Output = $return_ty;
230                fn op_mul(self, other: &Value) -> Self::Output {
231                    $mul(other, self as _)
232                }
233            }
234
235            impl Mul<&&Value> for $ty {
236                type Output = $return_ty;
237                fn op_mul(self, other: &&Value) -> Self::Output {
238                    $mul(*other, self as _)
239                }
240            }
241
242            impl<'a> Mul<$ty> for &'a Value {
243                type Output = $return_ty;
244                fn op_mul(self, other: $ty) -> Self::Output {
245                    $mul(self, other as _)
246                }
247            }
248
249            impl<'a> Mul<&$ty> for &'a Value {
250                type Output = $return_ty;
251                fn op_mul(self, other: &$ty) -> Self::Output {
252                    $mul(self, *other as _)
253                }
254            }
255        )*)*
256    }
257}
258
259impl_numeric_mul! {
260    op_mul_u64[u8 u16 u32 u64] -> u64
261    op_mul_i64[i8 i16 i32 i64 isize] -> i64
262    op_mul_f64[f32 f64] -> f64
263}
264
265macro_rules! mul_self {
266    ([$($ty:ty)*]) => {
267        $(
268impl Mul<$ty> for $ty{
269         type Output = $ty;
270      fn op_mul(self, rhs: $ty) -> Self::Output {
271        self * rhs
272      }
273    }
274impl Mul<&$ty> for $ty{
275         type Output = $ty;
276      fn op_mul(self, rhs: &$ty) -> Self::Output {
277        self * *rhs
278      }
279    }
280impl Mul<$ty> for &$ty{
281         type Output = $ty;
282      fn op_mul(self, rhs: $ty) -> Self::Output {
283        *self * rhs
284      }
285    }
286impl Mul<&$ty> for &$ty{
287         type Output = $ty;
288      fn op_mul(self, rhs: &$ty) -> Self::Output {
289        *self * *rhs
290      }
291    }
292        )*
293    };
294}
295mul_self!([u8 u16 u32 u64]);
296mul_self!([i8 i16 i32 i64 isize]);
297mul_self!([f32 f64]);