rbatis_codegen/
ops_bit_or.rs

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