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