rbatis_codegen/
ops_rem.rs1use crate::ops::AsProxy;
2use crate::ops::Rem;
3use rbs::Value;
4
5fn op_rem_value(left: Value, rhs: Value) -> Value {
6 match left {
7 Value::I32(s) => {
8 let rhs = rhs.i32();
9 Value::I32(s % rhs)
10 }
11 Value::I64(s) => {
12 let rhs = rhs.i64();
13 Value::I64(s % rhs)
14 }
15 Value::U32(s) => {
16 let rhs = rhs.u32();
17 Value::U32(s % rhs)
18 }
19 Value::U64(s) => {
20 let rhs = rhs.u64();
21 Value::U64(s % rhs)
22 }
23 Value::F32(s) => {
24 let rhs = rhs.f64() as f32;
25 Value::F32(s % rhs)
26 }
27 Value::F64(s) => {
28 let rhs = rhs.f64();
29 Value::F64(s % rhs)
30 }
31 Value::Ext(_, e) => op_rem_value(*e, rhs),
32 _ => Value::Null,
33 }
34}
35impl Rem<Value> for Value {
37 type Output = Value;
38 fn op_rem(self, rhs: Value) -> Self::Output {
39 op_rem_value(self, rhs)
40 }
41}
42
43impl Rem<&Value> for Value {
44 type Output = Value;
45 fn op_rem(self, rhs: &Value) -> Self::Output {
46 op_rem_value(self, rhs.to_owned())
47 }
48}
49
50impl Rem<&&Value> for Value {
51 type Output = Value;
52 fn op_rem(self, rhs: &&Value) -> Self::Output {
53 op_rem_value(self, (*rhs).to_owned())
54 }
55}
56
57impl Rem<Value> for &Value {
58 type Output = Value;
59 fn op_rem(self, rhs: Value) -> Self::Output {
60 op_rem_value(self.to_owned(), rhs)
61 }
62}
63
64impl Rem<&Value> for &Value {
65 type Output = Value;
66 fn op_rem(self, rhs: &Value) -> Self::Output {
67 op_rem_value(self.to_owned(), rhs.to_owned())
68 }
69}
70
71impl Rem<&&Value> for &Value {
72 type Output = Value;
73 fn op_rem(self, rhs: &&Value) -> Self::Output {
74 op_rem_value(self.to_owned(), (*rhs).to_owned())
75 }
76}
77
78fn op_rem_u64(value: &Value, other: u64) -> u64 {
79 value.u64() % other
80}
81
82fn op_rem_i64(value: &Value, other: i64) -> i64 {
83 value.i64() % other
84}
85
86fn op_rem_f64(value: &Value, other: f64) -> f64 {
87 value.f64() % other
88}
89
90fn op_rem_u64_value(value: &Value, other: u64) -> u64 {
91 other % value.u64()
92}
93
94fn op_rem_i64_value(value: &Value, other: i64) -> i64 {
95 other % value.i64()
96}
97
98fn op_rem_f64_value(value: &Value, other: f64) -> f64 {
99 other % value.f64()
100}
101
102macro_rules! impl_numeric_rem {
103 ($($rem:ident,$rem_value:ident [$($ty:ty)*]-> $return_ty:ty)*) => {
104 $($(
105 impl Rem<$ty> for Value {
106 type Output = $return_ty;
107 fn op_rem(self, other: $ty) -> Self::Output {
108 $rem(&self, other as _)
109 }
110 }
111
112 impl Rem<&$ty> for Value {
113 type Output = $return_ty;
114 fn op_rem(self, other: &$ty) -> Self::Output {
115 $rem(&self, *other as _)
116 }
117 }
118
119 impl<'a> Rem<$ty> for &'a Value {
120 type Output = $return_ty;
121 fn op_rem(self, other: $ty) -> Self::Output {
122 $rem(self, other as _)
123 }
124 }
125
126 impl<'a> Rem<&$ty> for &'a Value {
127 type Output = $return_ty;
128 fn op_rem(self, other: &$ty) -> Self::Output {
129 $rem(self, *other as _)
130 }
131 }
132
133 impl Rem<Value> for $ty {
134 type Output = $return_ty;
135 fn op_rem(self, other: Value) -> Self::Output {
136 $rem_value(&other, self as _)
137 }
138 }
139
140 impl Rem<&Value> for $ty {
141 type Output = $return_ty;
142 fn op_rem(self, other: &Value) -> Self::Output {
143 $rem_value(other, self as _)
144 }
145 }
146
147 impl Rem<Value> for &$ty {
148 type Output = $return_ty;
149 fn op_rem(self, other: Value) -> Self::Output {
150 $rem_value(&other, *self as _)
151 }
152 }
153
154 impl Rem<&Value> for &$ty {
155 type Output = $return_ty;
156 fn op_rem(self, other: &Value) -> Self::Output {
157 $rem_value(other, *self as _)
158 }
159 }
160 impl Rem<&&Value> for $ty {
162 type Output = $return_ty;
163 fn op_rem(self, other: &&Value) -> Self::Output {
164 $rem_value(other, self as _)
165 }
166 }
167 )*)*
168 }
169}
170
171impl_numeric_rem! {
172 op_rem_u64,op_rem_u64_value[u8 u16 u32 u64] -> u64
173 op_rem_i64,op_rem_i64_value[i8 i16 i32 i64 isize usize] -> i64
174 op_rem_f64,op_rem_f64_value[f32 f64] -> f64
175}
176
177macro_rules! self_rem {
178 ([$($ty:ty)*]) => {
179 $(
180impl Rem<$ty> for $ty{
181 type Output = $ty;
182 fn op_rem(self, rhs: $ty) -> Self::Output {
183 self % rhs
184 }
185}
186impl Rem<&$ty> for $ty{
187 type Output = $ty;
188 fn op_rem(self, rhs: &$ty) -> Self::Output {
189 self % *rhs
190 }
191}
192impl Rem<$ty> for &$ty{
193 type Output = $ty;
194 fn op_rem(self, rhs: $ty) -> Self::Output {
195 *self % rhs
196 }
197}
198impl Rem<&$ty> for &$ty{
199 type Output = $ty;
200 fn op_rem(self, rhs: &$ty) -> Self::Output {
201 *self % *rhs
202 }
203}
204 )*
205 };
206}
207self_rem!([u8 u16 u32 u64]);
208self_rem!([i8 i16 i32 i64 isize usize]);
209self_rem!([f32 f64]);