1use ordered_float::{FloatCore, OrderedFloat};
2
3use super::Array;
4
5#[inline]
6fn map_option_ordered_float_vec<T>(
7 vec: &[Option<T>],
8) -> impl Iterator<Item = Option<OrderedFloat<T>>> + '_
9where
10 T: FloatCore,
11{
12 vec.iter().copied().map(|x| x.map(OrderedFloat))
13}
14
15#[inline]
16fn cmp_option_ordered_float_vec<T>(left: &[Option<T>], right: &[Option<T>]) -> bool
17where
18 T: FloatCore,
19{
20 map_option_ordered_float_vec(left).eq(map_option_ordered_float_vec(right))
21}
22
23impl PartialEq for Array {
24 fn eq(&self, other: &Self) -> bool {
25 match (self, other) {
26 (Self::Bool(l0), Self::Bool(r0)) => l0 == r0,
27 (Self::TinyInt(l0), Self::TinyInt(r0)) => l0 == r0,
28 (Self::SmallInt(l0), Self::SmallInt(r0)) => l0 == r0,
29 (Self::Int(l0), Self::Int(r0)) => l0 == r0,
30 (Self::BigInt(l0), Self::BigInt(r0)) => l0 == r0,
31 (Self::TinyUnsigned(l0), Self::TinyUnsigned(r0)) => l0 == r0,
32 (Self::SmallUnsigned(l0), Self::SmallUnsigned(r0)) => l0 == r0,
33 (Self::Unsigned(l0), Self::Unsigned(r0)) => l0 == r0,
34 (Self::BigUnsigned(l0), Self::BigUnsigned(r0)) => l0 == r0,
35 (Self::Float(l0), Self::Float(r0)) => cmp_option_ordered_float_vec(l0, r0),
36 (Self::Double(l0), Self::Double(r0)) => cmp_option_ordered_float_vec(l0, r0),
37 (Self::String(l0), Self::String(r0)) => l0 == r0,
38 (Self::Char(l0), Self::Char(r0)) => l0 == r0,
39 (Self::Bytes(l0), Self::Bytes(r0)) => l0 == r0,
40 (Self::Enum(l0), Self::Enum(r0)) => l0 == r0,
41 #[cfg(feature = "with-json")]
42 (Self::Json(l0), Self::Json(r0)) => l0 == r0,
43 #[cfg(feature = "with-chrono")]
44 (Self::ChronoDate(l0), Self::ChronoDate(r0)) => l0 == r0,
45 #[cfg(feature = "with-chrono")]
46 (Self::ChronoTime(l0), Self::ChronoTime(r0)) => l0 == r0,
47 #[cfg(feature = "with-chrono")]
48 (Self::ChronoDateTime(l0), Self::ChronoDateTime(r0)) => l0 == r0,
49 #[cfg(feature = "with-chrono")]
50 (Self::ChronoDateTimeUtc(l0), Self::ChronoDateTimeUtc(r0)) => l0 == r0,
51 #[cfg(feature = "with-chrono")]
52 (Self::ChronoDateTimeLocal(l0), Self::ChronoDateTimeLocal(r0)) => l0 == r0,
53 #[cfg(feature = "with-chrono")]
54 (Self::ChronoDateTimeWithTimeZone(l0), Self::ChronoDateTimeWithTimeZone(r0)) => {
55 l0 == r0
56 }
57 #[cfg(feature = "with-time")]
58 (Self::TimeDate(l0), Self::TimeDate(r0)) => l0 == r0,
59 #[cfg(feature = "with-time")]
60 (Self::TimeTime(l0), Self::TimeTime(r0)) => l0 == r0,
61 #[cfg(feature = "with-time")]
62 (Self::TimeDateTime(l0), Self::TimeDateTime(r0)) => l0 == r0,
63 #[cfg(feature = "with-time")]
64 (Self::TimeDateTimeWithTimeZone(l0), Self::TimeDateTimeWithTimeZone(r0)) => l0 == r0,
65 #[cfg(feature = "with-jiff")]
66 (Self::JiffDate(l0), Self::JiffDate(r0)) => l0 == r0,
67 #[cfg(feature = "with-jiff")]
68 (Self::JiffTime(l0), Self::JiffTime(r0)) => l0 == r0,
69 #[cfg(feature = "with-jiff")]
70 (Self::JiffDateTime(l0), Self::JiffDateTime(r0)) => l0 == r0,
71 #[cfg(feature = "with-jiff")]
72 (Self::JiffTimestamp(l0), Self::JiffTimestamp(r0)) => l0 == r0,
73 #[cfg(feature = "with-jiff")]
74 (Self::JiffZoned(l0), Self::JiffZoned(r0)) => l0 == r0,
75 #[cfg(feature = "with-uuid")]
76 (Self::Uuid(l0), Self::Uuid(r0)) => l0 == r0,
77 #[cfg(feature = "with-rust_decimal")]
78 (Self::Decimal(l0), Self::Decimal(r0)) => l0 == r0,
79 #[cfg(feature = "with-bigdecimal")]
80 (Self::BigDecimal(l0), Self::BigDecimal(r0)) => l0 == r0,
81 #[cfg(feature = "with-ipnetwork")]
82 (Self::IpNetwork(l0), Self::IpNetwork(r0)) => l0 == r0,
83 #[cfg(feature = "with-mac_address")]
84 (Self::MacAddress(l0), Self::MacAddress(r0)) => l0 == r0,
85 (Self::Null(l0), Self::Null(r0)) => l0 == r0,
86 _ => false,
87 }
88 }
89}
90
91impl Eq for Array {}
92
93impl std::hash::Hash for Array {
94 fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
95 use ordered_float::OrderedFloat;
96
97 std::mem::discriminant(self).hash(state);
98 match self {
99 Array::Bool(items) => items.hash(state),
100 Array::TinyInt(items) => items.hash(state),
101 Array::SmallInt(items) => items.hash(state),
102 Array::Int(items) => items.hash(state),
103 Array::BigInt(items) => items.hash(state),
104 Array::TinyUnsigned(items) => items.hash(state),
105 Array::SmallUnsigned(items) => items.hash(state),
106 Array::Unsigned(items) => items.hash(state),
107 Array::BigUnsigned(items) => items.hash(state),
108 Array::Float(items) => {
109 for x in items.iter() {
110 x.map(OrderedFloat).hash(state)
111 }
112 }
113 Array::Double(items) => {
114 for x in items.iter() {
115 x.map(OrderedFloat).hash(state)
116 }
117 }
118 Array::String(items) => items.hash(state),
119 Array::Char(items) => items.hash(state),
120 Array::Bytes(items) => items.hash(state),
121 Array::Enum(items) => items.hash(state),
122 #[cfg(feature = "with-json")]
123 Array::Json(items) => items.hash(state),
124 #[cfg(feature = "with-chrono")]
125 Array::ChronoDate(items) => items.hash(state),
126 #[cfg(feature = "with-chrono")]
127 Array::ChronoTime(items) => items.hash(state),
128 #[cfg(feature = "with-chrono")]
129 Array::ChronoDateTime(items) => items.hash(state),
130 #[cfg(feature = "with-chrono")]
131 Array::ChronoDateTimeUtc(items) => items.hash(state),
132 #[cfg(feature = "with-chrono")]
133 Array::ChronoDateTimeLocal(items) => items.hash(state),
134 #[cfg(feature = "with-chrono")]
135 Array::ChronoDateTimeWithTimeZone(items) => items.hash(state),
136 #[cfg(feature = "with-time")]
137 Array::TimeDate(items) => items.hash(state),
138 #[cfg(feature = "with-time")]
139 Array::TimeTime(items) => items.hash(state),
140 #[cfg(feature = "with-time")]
141 Array::TimeDateTime(items) => items.hash(state),
142 #[cfg(feature = "with-time")]
143 Array::TimeDateTimeWithTimeZone(items) => items.hash(state),
144 #[cfg(feature = "with-jiff")]
145 Array::JiffDate(items) => items.hash(state),
146 #[cfg(feature = "with-jiff")]
147 Array::JiffTime(items) => items.hash(state),
148 #[cfg(feature = "with-jiff")]
149 Array::JiffDateTime(items) => items.hash(state),
150 #[cfg(feature = "with-jiff")]
151 Array::JiffTimestamp(items) => items.hash(state),
152 #[cfg(feature = "with-jiff")]
153 Array::JiffZoned(items) => items.hash(state),
154 #[cfg(feature = "with-uuid")]
155 Array::Uuid(items) => items.hash(state),
156 #[cfg(feature = "with-rust_decimal")]
157 Array::Decimal(items) => items.hash(state),
158 #[cfg(feature = "with-bigdecimal")]
159 Array::BigDecimal(items) => items.hash(state),
160 #[cfg(feature = "with-ipnetwork")]
161 Array::IpNetwork(items) => items.hash(state),
162 #[cfg(feature = "with-mac_address")]
163 Array::MacAddress(items) => items.hash(state),
164 Array::Null(ty) => ty.hash(state),
165 }
166 }
167}