rbatis_codegen/
ops_bit_and.rs

1use crate::ops::BitAnd;
2use rbs::Value;
3
4impl BitAnd for Value {
5    type Output = bool;
6
7    fn op_bitand(self, rhs: Self) -> Self::Output {
8        self.as_bool().unwrap_or(false) & rhs.as_bool().unwrap_or(false)
9    }
10}
11
12impl BitAnd<Value> for bool {
13    type Output = bool;
14
15    fn op_bitand(self, rhs: Value) -> Self::Output {
16        self & rhs.as_bool().unwrap_or(false)
17    }
18}
19
20//ref value
21impl BitAnd<Value> for &Value {
22    type Output = bool;
23
24    fn op_bitand(self, rhs: Value) -> Self::Output {
25        self.as_bool().unwrap_or(false) & rhs.as_bool().unwrap_or(false)
26    }
27}
28
29impl BitAnd<&Value> for &Value {
30    type Output = bool;
31
32    fn op_bitand(self, rhs: &Value) -> Self::Output {
33        self.as_bool().unwrap_or(false) & rhs.as_bool().unwrap_or(false)
34    }
35}
36
37impl BitAnd<&&Value> for &Value {
38    type Output = bool;
39
40    fn op_bitand(self, rhs: &&Value) -> Self::Output {
41        self.as_bool().unwrap_or(false) & rhs.as_bool().unwrap_or(false)
42    }
43}
44
45impl BitAnd<bool> for &Value {
46    type Output = bool;
47
48    fn op_bitand(self, rhs: bool) -> Self::Output {
49        self.as_bool().unwrap_or(false) & rhs
50    }
51}
52
53//rhs ref
54impl BitAnd<&Value> for Value {
55    type Output = bool;
56
57    fn op_bitand(self, rhs: &Value) -> Self::Output {
58        self.as_bool().unwrap_or(false) & rhs.as_bool().unwrap_or(false)
59    }
60}
61
62impl BitAnd<&Value> for bool {
63    type Output = bool;
64
65    fn op_bitand(self, rhs: &Value) -> Self::Output {
66        self & rhs.as_bool().unwrap_or(false)
67    }
68}
69
70impl BitAnd<&&Value> for Value {
71    type Output = bool;
72
73    fn op_bitand(self, rhs: &&Value) -> Self::Output {
74        self.as_bool().unwrap_or(false) & rhs.as_bool().unwrap_or(false)
75    }
76}
77
78impl BitAnd<&&Value> for bool {
79    type Output = bool;
80
81    fn op_bitand(self, rhs: &&Value) -> Self::Output {
82        self & rhs.as_bool().unwrap_or(false)
83    }
84}
85
86fn op_bit_and_u64(v: &Value, other: u64) -> u64 {
87    std::ops::BitAnd::bitand(v.as_u64().unwrap_or_default(), other)
88}
89
90fn op_bit_and_i64(v: &Value, other: i64) -> i64 {
91    std::ops::BitAnd::bitand(v.as_i64().unwrap_or_default(), other)
92}
93
94macro_rules! impl_numeric_bitand {
95    ($($eq:ident [$($ty:ty)*]-> $return_ty:ty)*) => {
96        $($(
97            impl BitAnd<$ty> for Value {
98                type Output = $return_ty;
99                fn op_bitand(self, other: $ty) -> Self::Output {
100                    $eq(&self, other as _)
101                }
102            }
103
104            impl BitAnd<&$ty> for Value {
105                type Output = $return_ty;
106                fn op_bitand(self, other: &$ty) -> Self::Output {
107                    $eq(&self, *other as _)
108                }
109            }
110
111            impl<'a> BitAnd<$ty> for &'a Value {
112                type Output = $return_ty;
113                fn op_bitand(self, other: $ty) -> Self::Output {
114                    $eq(self, other as _)
115                }
116            }
117
118            impl<'a> BitAnd<&$ty> for &'a Value {
119                type Output = $return_ty;
120                fn op_bitand(self, other: &$ty) -> Self::Output {
121                    $eq(self, *other as _)
122                }
123            }
124
125            impl BitAnd<Value> for $ty {
126                type Output = $return_ty;
127                fn op_bitand(self, other: Value) -> Self::Output {
128                    $eq(&other, self as _)
129                }
130            }
131
132            impl BitAnd<&Value> for $ty {
133                type Output = $return_ty;
134                fn op_bitand(self, other: &Value) -> Self::Output {
135                    $eq(other, self as _)
136                }
137            }
138
139            impl BitAnd<Value> for &$ty {
140                type Output = $return_ty;
141                fn op_bitand(self, other: Value) -> Self::Output {
142                    $eq(&other, *self as _)
143                }
144            }
145
146            impl BitAnd<&Value> for &$ty {
147                type Output = $return_ty;
148                fn op_bitand(self, other: &Value) -> Self::Output {
149                    $eq(other, *self as _)
150                }
151            }
152
153            // for unary
154            impl BitAnd<&&Value> for $ty {
155                type Output = $return_ty;
156                fn op_bitand(self, other: &&Value) -> Self::Output {
157                    $eq(other, self as _)
158                }
159            }
160        )*)*
161    }
162}
163
164impl_numeric_bitand! {
165    op_bit_and_u64[u8 u16 u32 u64] -> u64
166    op_bit_and_i64[i8 i16 i32 i64 isize usize] -> i64
167}
168
169macro_rules! self_bitand {
170    ([$($ty:ty)*]) => {
171        $(
172impl BitAnd<$ty> for $ty{
173      type Output = $ty;
174      fn op_bitand(self, rhs: $ty) -> Self::Output {
175        self & rhs
176      }
177}
178impl BitAnd<&$ty> for $ty{
179      type Output = $ty;
180      fn op_bitand(self, rhs: &$ty) -> Self::Output {
181        self  &  *rhs
182      }
183}
184impl BitAnd<$ty> for &$ty{
185      type Output = $ty;
186      fn op_bitand(self, rhs: $ty) -> Self::Output {
187        *self  &  rhs
188      }
189}
190impl BitAnd<&$ty> for &$ty{
191      type Output = $ty;
192      fn op_bitand(self, rhs: &$ty) -> Self::Output {
193        *self & *rhs
194      }
195}
196        )*
197    };
198}
199self_bitand!([u8 u16 u32 u64]);
200self_bitand!([i8 i16 i32 i64 isize usize]);