Skip to main content

smol_bytes/utf8_buffer/
cmp.rs

1use core::cmp::Ordering;
2
3use super::*;
4
5impl PartialEq for Utf8Buffer {
6  #[cfg_attr(not(coverage), inline(always))]
7  fn eq(&self, other: &Self) -> bool {
8    self.as_str() == other.as_str()
9  }
10}
11
12impl Eq for Utf8Buffer {}
13
14impl PartialOrd for Utf8Buffer {
15  #[cfg_attr(not(coverage), inline(always))]
16  fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
17    Some(self.cmp(other))
18  }
19}
20
21impl Ord for Utf8Buffer {
22  #[cfg_attr(not(coverage), inline(always))]
23  fn cmp(&self, other: &Self) -> Ordering {
24    self.as_str().cmp(other.as_str())
25  }
26}
27
28impl PartialEq<str> for Utf8Buffer {
29  #[cfg_attr(not(coverage), inline(always))]
30  fn eq(&self, other: &str) -> bool {
31    self.as_str() == other
32  }
33}
34
35impl PartialEq<Utf8Buffer> for str {
36  #[cfg_attr(not(coverage), inline(always))]
37  fn eq(&self, other: &Utf8Buffer) -> bool {
38    self == other.as_str()
39  }
40}
41
42impl PartialEq<&str> for Utf8Buffer {
43  #[cfg_attr(not(coverage), inline(always))]
44  fn eq(&self, other: &&str) -> bool {
45    self.as_str() == *other
46  }
47}
48
49impl PartialEq<Utf8Buffer> for &str {
50  #[cfg_attr(not(coverage), inline(always))]
51  fn eq(&self, other: &Utf8Buffer) -> bool {
52    *self == other.as_str()
53  }
54}
55
56impl PartialOrd<str> for Utf8Buffer {
57  #[cfg_attr(not(coverage), inline(always))]
58  fn partial_cmp(&self, other: &str) -> Option<Ordering> {
59    self.as_str().partial_cmp(other)
60  }
61}
62
63impl PartialOrd<Utf8Buffer> for str {
64  #[cfg_attr(not(coverage), inline(always))]
65  fn partial_cmp(&self, other: &Utf8Buffer) -> Option<Ordering> {
66    self.partial_cmp(other.as_str())
67  }
68}
69
70#[cfg(any(feature = "std", feature = "alloc"))]
71const _: () = {
72  use std::string::String;
73
74  impl PartialEq<String> for Utf8Buffer {
75    #[cfg_attr(not(coverage), inline(always))]
76    fn eq(&self, other: &String) -> bool {
77      self.as_str() == other.as_str()
78    }
79  }
80
81  impl PartialEq<Utf8Buffer> for String {
82    #[cfg_attr(not(coverage), inline(always))]
83    fn eq(&self, other: &Utf8Buffer) -> bool {
84      self.as_str() == other.as_str()
85    }
86  }
87
88  impl PartialOrd<String> for Utf8Buffer {
89    #[cfg_attr(not(coverage), inline(always))]
90    fn partial_cmp(&self, other: &String) -> Option<Ordering> {
91      self.as_str().partial_cmp(other.as_str())
92    }
93  }
94
95  impl PartialOrd<Utf8Buffer> for String {
96    #[cfg_attr(not(coverage), inline(always))]
97    fn partial_cmp(&self, other: &Utf8Buffer) -> Option<Ordering> {
98      self.as_str().partial_cmp(other.as_str())
99    }
100  }
101};
102
103impl core::hash::Hash for Utf8Buffer {
104  fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
105    self.as_str().hash(state);
106  }
107}
108
109// Cross-type equality with the heap-capable wrappers. Gated because
110// `Utf8Bytes` and `Utf8BytesMut` require `std` or `alloc`.
111#[cfg(any(feature = "std", feature = "alloc"))]
112const _: () = {
113  use crate::Utf8BytesMut;
114  use crate::bytes::{RawBytes, strategy::ImmutableStorage};
115
116  impl<S> PartialEq<crate::utf8_bytes::Utf8Bytes<S>> for Utf8Buffer
117  where
118    RawBytes<S>: ImmutableStorage,
119  {
120    #[cfg_attr(not(coverage), inline(always))]
121    fn eq(&self, other: &crate::utf8_bytes::Utf8Bytes<S>) -> bool {
122      self.as_str() == other.as_str()
123    }
124  }
125
126  impl<S> PartialEq<Utf8Buffer> for crate::utf8_bytes::Utf8Bytes<S>
127  where
128    RawBytes<S>: ImmutableStorage,
129  {
130    #[cfg_attr(not(coverage), inline(always))]
131    fn eq(&self, other: &Utf8Buffer) -> bool {
132      self.as_str() == other.as_str()
133    }
134  }
135
136  impl PartialEq<Utf8BytesMut> for Utf8Buffer {
137    #[cfg_attr(not(coverage), inline(always))]
138    fn eq(&self, other: &Utf8BytesMut) -> bool {
139      self.as_str() == other.as_str()
140    }
141  }
142
143  impl PartialEq<Utf8Buffer> for Utf8BytesMut {
144    #[cfg_attr(not(coverage), inline(always))]
145    fn eq(&self, other: &Utf8Buffer) -> bool {
146      self.as_str() == other.as_str()
147    }
148  }
149};