mybatis_sql/
ops_eq.rs

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