serde_yaml/value/
partial_eq.rs
1use crate::Value;
2
3impl PartialEq<str> for Value {
4 fn eq(&self, other: &str) -> bool {
13 self.as_str().map_or(false, |s| s == other)
14 }
15}
16
17impl<'a> PartialEq<&'a str> for Value {
18 fn eq(&self, other: &&str) -> bool {
27 self.as_str().map_or(false, |s| s == *other)
28 }
29}
30
31impl PartialEq<String> for Value {
32 fn eq(&self, other: &String) -> bool {
41 self.as_str().map_or(false, |s| s == other)
42 }
43}
44
45impl PartialEq<bool> for Value {
46 fn eq(&self, other: &bool) -> bool {
55 self.as_bool().map_or(false, |b| b == *other)
56 }
57}
58
59macro_rules! partialeq_numeric {
60 ($([$($ty:ty)*], $conversion:ident, $base:ty)*) => {
61 $($(
62 impl PartialEq<$ty> for Value {
63 fn eq(&self, other: &$ty) -> bool {
64 self.$conversion().map_or(false, |i| i == (*other as $base))
65 }
66 }
67
68 impl<'a> PartialEq<$ty> for &'a Value {
69 fn eq(&self, other: &$ty) -> bool {
70 self.$conversion().map_or(false, |i| i == (*other as $base))
71 }
72 }
73
74 impl<'a> PartialEq<$ty> for &'a mut Value {
75 fn eq(&self, other: &$ty) -> bool {
76 self.$conversion().map_or(false, |i| i == (*other as $base))
77 }
78 }
79 )*)*
80 }
81}
82
83partialeq_numeric! {
84 [i8 i16 i32 i64 isize], as_i64, i64
85 [u8 u16 u32 u64 usize], as_u64, u64
86 [f32 f64], as_f64, f64
87}