]> git.proxmox.com Git - rustc.git/blame - src/vendor/serde_json/src/value/partial_eq.rs
New upstream version 1.22.1+dfsg1
[rustc.git] / src / vendor / serde_json / src / value / partial_eq.rs
CommitLineData
041b39d2
XL
1// Copyright 2017 Serde Developers
2//
3// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
4// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
5// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
6// option. This file may not be copied, modified, or distributed
7// except according to those terms.
8
9use super::Value;
10
11impl PartialEq<str> for Value {
12 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 {
19 self.as_str().map_or(false, |s| s == *other)
20 }
21}
22
23impl PartialEq<Value> for str {
24 fn eq(&self, other: &Value) -> bool {
25 other.as_str().map_or(false, |s| s == self)
26 }
27}
28
29impl<'a> PartialEq<Value> for &'a str {
30 fn eq(&self, other: &Value) -> bool {
31 other.as_str().map_or(false, |s| s == *self)
32 }
33}
34
35impl PartialEq<String> for Value {
36 fn eq(&self, other: &String) -> bool {
37 self.as_str().map_or(false, |s| s == other)
38 }
39}
40
41
42impl PartialEq<Value> for String {
43 fn eq(&self, other: &Value) -> bool {
44 other.as_str().map_or(false, |s| s == self)
45 }
46}
47
48macro_rules! partialeq_numeric {
49 ($([$($ty:ty)*], $conversion:ident, $base:ty)*) => {
50 $($(
51 impl PartialEq<$ty> for Value {
52 fn eq(&self, other: &$ty) -> bool {
53 self.$conversion().map_or(false, |i| i == (*other as $base))
54 }
55 }
56
57 impl PartialEq<Value> for $ty {
58 fn eq(&self, other: &Value) -> bool {
59 other.$conversion().map_or(false, |i| i == (*self as $base))
60 }
61 }
62
63 impl<'a> PartialEq<$ty> for &'a Value {
64 fn eq(&self, other: &$ty) -> bool {
65 self.$conversion().map_or(false, |i| i == (*other as $base))
66 }
67 }
68
69 impl<'a> PartialEq<$ty> for &'a mut Value {
70 fn eq(&self, other: &$ty) -> bool {
71 self.$conversion().map_or(false, |i| i == (*other as $base))
72 }
73 }
74 )*)*
75 }
76}
77
78partialeq_numeric! {
79 [i8 i16 i32 i64 isize], as_i64, i64
80 [u8 u16 u32 u64 usize], as_u64, u64
81 [f32 f64], as_f64, f64
ea8adc8c 82 [bool], as_bool, bool
041b39d2 83}