1 use super::Value;
2 use alloc::string::String;
3
eq_i64(value: &Value, other: i64) -> bool4 fn eq_i64(value: &Value, other: i64) -> bool {
5 value.as_i64().map_or(false, |i| i == other)
6 }
7
eq_u64(value: &Value, other: u64) -> bool8 fn eq_u64(value: &Value, other: u64) -> bool {
9 value.as_u64().map_or(false, |i| i == other)
10 }
11
eq_f64(value: &Value, other: f64) -> bool12 fn eq_f64(value: &Value, other: f64) -> bool {
13 value.as_f64().map_or(false, |i| i == other)
14 }
15
eq_bool(value: &Value, other: bool) -> bool16 fn eq_bool(value: &Value, other: bool) -> bool {
17 value.as_bool().map_or(false, |i| i == other)
18 }
19
eq_str(value: &Value, other: &str) -> bool20 fn eq_str(value: &Value, other: &str) -> bool {
21 value.as_str().map_or(false, |i| i == other)
22 }
23
24 impl PartialEq<str> for Value {
eq(&self, other: &str) -> bool25 fn eq(&self, other: &str) -> bool {
26 eq_str(self, other)
27 }
28 }
29
30 impl<'a> PartialEq<&'a str> for Value {
eq(&self, other: &&str) -> bool31 fn eq(&self, other: &&str) -> bool {
32 eq_str(self, *other)
33 }
34 }
35
36 impl PartialEq<Value> for str {
eq(&self, other: &Value) -> bool37 fn eq(&self, other: &Value) -> bool {
38 eq_str(other, self)
39 }
40 }
41
42 impl<'a> PartialEq<Value> for &'a str {
eq(&self, other: &Value) -> bool43 fn eq(&self, other: &Value) -> bool {
44 eq_str(other, *self)
45 }
46 }
47
48 impl PartialEq<String> for Value {
eq(&self, other: &String) -> bool49 fn eq(&self, other: &String) -> bool {
50 eq_str(self, other.as_str())
51 }
52 }
53
54 impl PartialEq<Value> for String {
eq(&self, other: &Value) -> bool55 fn eq(&self, other: &Value) -> bool {
56 eq_str(other, self.as_str())
57 }
58 }
59
60 macro_rules! partialeq_numeric {
61 ($($eq:ident [$($ty:ty)*])*) => {
62 $($(
63 impl PartialEq<$ty> for Value {
64 fn eq(&self, other: &$ty) -> bool {
65 $eq(self, *other as _)
66 }
67 }
68
69 impl PartialEq<Value> for $ty {
70 fn eq(&self, other: &Value) -> bool {
71 $eq(other, *self as _)
72 }
73 }
74
75 impl<'a> PartialEq<$ty> for &'a Value {
76 fn eq(&self, other: &$ty) -> bool {
77 $eq(*self, *other as _)
78 }
79 }
80
81 impl<'a> PartialEq<$ty> for &'a mut Value {
82 fn eq(&self, other: &$ty) -> bool {
83 $eq(*self, *other as _)
84 }
85 }
86 )*)*
87 }
88 }
89
90 partialeq_numeric! {
91 eq_i64[i8 i16 i32 i64 isize]
92 eq_u64[u8 u16 u32 u64 usize]
93 eq_f64[f32 f64]
94 eq_bool[bool]
95 }
96