1use std::borrow::Borrow;
2
3use value_trait::{base::ValueAsScalar, derived::TypedScalarValue};
4
5use super::Value;
6
7#[allow(clippy::cast_sign_loss, clippy::default_trait_access)]
8impl<'tape, 'input> PartialEq for Value<'tape, 'input> {
9 #[cfg_attr(not(feature = "no-inline"), inline)]
10 #[must_use]
11 fn eq(&self, other: &Self) -> bool {
12 self.0 == other.0
13 }
14}
15
16impl<'tape, 'input, T> PartialEq<&T> for Value<'tape, 'input>
17where
18 Value<'tape, 'input>: PartialEq<T>,
19{
20 #[cfg_attr(not(feature = "no-inline"), inline)]
21 #[must_use]
22 fn eq(&self, other: &&T) -> bool {
23 self == *other
24 }
25}
26
27impl<'tape, 'input> PartialEq<()> for Value<'tape, 'input> {
28 #[cfg_attr(not(feature = "no-inline"), inline)]
29 #[must_use]
30 fn eq(&self, _other: &()) -> bool {
31 self.is_null()
32 }
33}
34
35impl<'tape, 'input> PartialEq<bool> for Value<'tape, 'input> {
36 #[cfg_attr(not(feature = "no-inline"), inline)]
37 #[must_use]
38 fn eq(&self, other: &bool) -> bool {
39 self.as_bool().map(|t| t.eq(other)).unwrap_or_default()
40 }
41}
42
43impl<'tape, 'input> PartialEq<str> for Value<'tape, 'input> {
44 #[cfg_attr(not(feature = "no-inline"), inline)]
45 #[must_use]
46 fn eq(&self, other: &str) -> bool {
47 self.as_str().map(|t| t.eq(other)).unwrap_or_default()
48 }
49}
50
51impl<'tape, 'input> PartialEq<&str> for Value<'tape, 'input> {
52 #[cfg_attr(not(feature = "no-inline"), inline)]
53 #[must_use]
54 fn eq(&self, other: &&str) -> bool {
55 self == *other
56 }
57}
58
59impl<'tape, 'input> PartialEq<String> for Value<'tape, 'input> {
60 #[cfg_attr(not(feature = "no-inline"), inline)]
61 #[must_use]
62 fn eq(&self, other: &String) -> bool {
63 self.as_str().map(|t| t.eq(other)).unwrap_or_default()
64 }
65}
66
67impl<'tape, 'input> PartialEq<i8> for Value<'tape, 'input> {
68 #[cfg_attr(not(feature = "no-inline"), inline)]
69 #[must_use]
70 fn eq(&self, other: &i8) -> bool {
71 self.as_i8().map(|t| t.eq(other)).unwrap_or_default()
72 }
73}
74
75impl<'tape, 'input> PartialEq<i16> for Value<'tape, 'input> {
76 #[cfg_attr(not(feature = "no-inline"), inline)]
77 #[must_use]
78 fn eq(&self, other: &i16) -> bool {
79 self.as_i16().map(|t| t.eq(other)).unwrap_or_default()
80 }
81}
82
83impl<'tape, 'input> PartialEq<i32> for Value<'tape, 'input> {
84 #[cfg_attr(not(feature = "no-inline"), inline)]
85 #[must_use]
86 fn eq(&self, other: &i32) -> bool {
87 self.as_i32().map(|t| t.eq(other)).unwrap_or_default()
88 }
89}
90
91impl<'tape, 'input> PartialEq<i64> for Value<'tape, 'input> {
92 #[cfg_attr(not(feature = "no-inline"), inline)]
93 #[must_use]
94 fn eq(&self, other: &i64) -> bool {
95 self.as_i64().map(|t| t.eq(other)).unwrap_or_default()
96 }
97}
98
99impl<'tape, 'input> PartialEq<i128> for Value<'tape, 'input> {
100 #[cfg_attr(not(feature = "no-inline"), inline)]
101 #[must_use]
102 fn eq(&self, other: &i128) -> bool {
103 self.as_i128().map(|t| t.eq(other)).unwrap_or_default()
104 }
105}
106
107impl<'tape, 'input> PartialEq<u8> for Value<'tape, 'input> {
108 #[cfg_attr(not(feature = "no-inline"), inline)]
109 #[must_use]
110 fn eq(&self, other: &u8) -> bool {
111 self.as_u8().map(|t| t.eq(other)).unwrap_or_default()
112 }
113}
114
115impl<'tape, 'input> PartialEq<u16> for Value<'tape, 'input> {
116 #[cfg_attr(not(feature = "no-inline"), inline)]
117 #[must_use]
118 fn eq(&self, other: &u16) -> bool {
119 self.as_u16().map(|t| t.eq(other)).unwrap_or_default()
120 }
121}
122
123impl<'tape, 'input> PartialEq<u32> for Value<'tape, 'input> {
124 #[cfg_attr(not(feature = "no-inline"), inline)]
125 #[must_use]
126 fn eq(&self, other: &u32) -> bool {
127 self.as_u32().map(|t| t.eq(other)).unwrap_or_default()
128 }
129}
130
131impl<'tape, 'input> PartialEq<u64> for Value<'tape, 'input> {
132 #[cfg_attr(not(feature = "no-inline"), inline)]
133 #[must_use]
134 fn eq(&self, other: &u64) -> bool {
135 self.as_u64().map(|t| t.eq(other)).unwrap_or_default()
136 }
137}
138
139impl<'tape, 'input> PartialEq<usize> for Value<'tape, 'input> {
140 #[cfg_attr(not(feature = "no-inline"), inline)]
141 #[must_use]
142 fn eq(&self, other: &usize) -> bool {
143 self.as_usize().map(|t| t.eq(other)).unwrap_or_default()
144 }
145}
146
147impl<'tape, 'input> PartialEq<u128> for Value<'tape, 'input> {
148 #[cfg_attr(not(feature = "no-inline"), inline)]
149 #[must_use]
150 fn eq(&self, other: &u128) -> bool {
151 self.as_u128().map(|t| t.eq(other)).unwrap_or_default()
152 }
153}
154
155impl<'tape, 'input> PartialEq<f32> for Value<'tape, 'input> {
156 #[cfg_attr(not(feature = "no-inline"), inline)]
157 #[must_use]
158 fn eq(&self, other: &f32) -> bool {
159 self.as_f32().map(|t| t.eq(other)).unwrap_or_default()
160 }
161}
162
163impl<'tape, 'input> PartialEq<f64> for Value<'tape, 'input> {
164 #[cfg_attr(not(feature = "no-inline"), inline)]
165 #[must_use]
166 fn eq(&self, other: &f64) -> bool {
167 self.as_f64().map(|t| t.eq(other)).unwrap_or_default()
168 }
169}
170
171impl<'tape, 'input, K, T, S> PartialEq<std::collections::HashMap<K, T, S>> for Value<'tape, 'input>
172where
173 K: Borrow<str> + std::hash::Hash + Eq,
174 for<'i> T: PartialEq<Value<'i, 'input>>,
175 S: std::hash::BuildHasher,
176{
177 #[cfg_attr(not(feature = "no-inline"), inline)]
178 #[must_use]
179 fn eq(&self, other: &std::collections::HashMap<K, T, S>) -> bool {
180 let Some(object) = self.as_object() else {
181 return false;
182 };
183 if object.len() != other.len() {
184 return false;
185 }
186 for (key, value) in &object {
187 if !other.get(key).map_or(false, |v| v == &value) {
188 return false;
189 }
190 }
191 true
192 }
193}