/rust/registry/src/index.crates.io-6f17d22bba15001f/winnow-0.6.18/src/stream/impls.rs
Line | Count | Source (jump to first uncovered line) |
1 | | macro_rules! impl_partial_eq { |
2 | | ($lhs:ty, $rhs:ty) => { |
3 | | #[allow(unused_lifetimes)] |
4 | | impl<'a> PartialEq<$rhs> for $lhs { |
5 | | #[inline] |
6 | 0 | fn eq(&self, other: &$rhs) -> bool { |
7 | 0 | let l = self.as_ref(); |
8 | 0 | let r: &Self = other.as_ref(); |
9 | 0 | PartialEq::eq(l, r) |
10 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq<[u8]>>::eq Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq<&[u8]>>::eq Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq<str>>::eq Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq<&str>>::eq Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq<[u8]>>::eq Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq<&[u8]>>::eq Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq<str>>::eq Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq<&str>>::eq Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq<[u8]>>::eq Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq<&[u8]>>::eq Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq<str>>::eq Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq<&str>>::eq Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq<[u8]>>::eq Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq<&[u8]>>::eq Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq<str>>::eq Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq<&str>>::eq |
11 | | } |
12 | | |
13 | | #[allow(unused_lifetimes)] |
14 | | impl<'a> PartialEq<$lhs> for $rhs { |
15 | | #[inline] |
16 | 0 | fn eq(&self, other: &$lhs) -> bool { |
17 | 0 | PartialEq::eq(other, self) |
18 | 0 | } Unexecuted instantiation: <[u8] as core::cmp::PartialEq<winnow::stream::Bytes>>::eq Unexecuted instantiation: <&[u8] as core::cmp::PartialEq<winnow::stream::Bytes>>::eq Unexecuted instantiation: <str as core::cmp::PartialEq<winnow::stream::Bytes>>::eq Unexecuted instantiation: <&str as core::cmp::PartialEq<winnow::stream::Bytes>>::eq Unexecuted instantiation: <[u8] as core::cmp::PartialEq<winnow::stream::BStr>>::eq Unexecuted instantiation: <&[u8] as core::cmp::PartialEq<winnow::stream::BStr>>::eq Unexecuted instantiation: <str as core::cmp::PartialEq<winnow::stream::BStr>>::eq Unexecuted instantiation: <&str as core::cmp::PartialEq<winnow::stream::BStr>>::eq Unexecuted instantiation: <[u8] as core::cmp::PartialEq<winnow::stream::Bytes>>::eq Unexecuted instantiation: <&[u8] as core::cmp::PartialEq<winnow::stream::Bytes>>::eq Unexecuted instantiation: <str as core::cmp::PartialEq<winnow::stream::Bytes>>::eq Unexecuted instantiation: <&str as core::cmp::PartialEq<winnow::stream::Bytes>>::eq Unexecuted instantiation: <[u8] as core::cmp::PartialEq<winnow::stream::BStr>>::eq Unexecuted instantiation: <&[u8] as core::cmp::PartialEq<winnow::stream::BStr>>::eq Unexecuted instantiation: <str as core::cmp::PartialEq<winnow::stream::BStr>>::eq Unexecuted instantiation: <&str as core::cmp::PartialEq<winnow::stream::BStr>>::eq |
19 | | } |
20 | | }; |
21 | | } |
22 | | |
23 | | macro_rules! impl_partial_ord { |
24 | | ($lhs:ty, $rhs:ty) => { |
25 | | #[allow(unused_lifetimes)] |
26 | | impl<'a> PartialOrd<$rhs> for $lhs { |
27 | | #[inline] |
28 | 0 | fn partial_cmp(&self, other: &$rhs) -> Option<Ordering> { |
29 | 0 | let l = self.as_ref(); |
30 | 0 | let r: &Self = other.as_ref(); |
31 | 0 | PartialOrd::partial_cmp(l, r) |
32 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd<[u8]>>::partial_cmp Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd<&[u8]>>::partial_cmp Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd<str>>::partial_cmp Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd<&str>>::partial_cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd<[u8]>>::partial_cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd<&[u8]>>::partial_cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd<str>>::partial_cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd<&str>>::partial_cmp Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd<[u8]>>::partial_cmp Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd<&[u8]>>::partial_cmp Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd<str>>::partial_cmp Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd<&str>>::partial_cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd<[u8]>>::partial_cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd<&[u8]>>::partial_cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd<str>>::partial_cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd<&str>>::partial_cmp |
33 | | } |
34 | | |
35 | | #[allow(unused_lifetimes)] |
36 | | impl<'a> PartialOrd<$lhs> for $rhs { |
37 | | #[inline] |
38 | 0 | fn partial_cmp(&self, other: &$lhs) -> Option<Ordering> { |
39 | 0 | PartialOrd::partial_cmp(other, self) |
40 | 0 | } Unexecuted instantiation: <[u8] as core::cmp::PartialOrd<winnow::stream::Bytes>>::partial_cmp Unexecuted instantiation: <&[u8] as core::cmp::PartialOrd<winnow::stream::Bytes>>::partial_cmp Unexecuted instantiation: <str as core::cmp::PartialOrd<winnow::stream::Bytes>>::partial_cmp Unexecuted instantiation: <&str as core::cmp::PartialOrd<winnow::stream::Bytes>>::partial_cmp Unexecuted instantiation: <[u8] as core::cmp::PartialOrd<winnow::stream::BStr>>::partial_cmp Unexecuted instantiation: <&[u8] as core::cmp::PartialOrd<winnow::stream::BStr>>::partial_cmp Unexecuted instantiation: <str as core::cmp::PartialOrd<winnow::stream::BStr>>::partial_cmp Unexecuted instantiation: <&str as core::cmp::PartialOrd<winnow::stream::BStr>>::partial_cmp Unexecuted instantiation: <[u8] as core::cmp::PartialOrd<winnow::stream::Bytes>>::partial_cmp Unexecuted instantiation: <&[u8] as core::cmp::PartialOrd<winnow::stream::Bytes>>::partial_cmp Unexecuted instantiation: <str as core::cmp::PartialOrd<winnow::stream::Bytes>>::partial_cmp Unexecuted instantiation: <&str as core::cmp::PartialOrd<winnow::stream::Bytes>>::partial_cmp Unexecuted instantiation: <[u8] as core::cmp::PartialOrd<winnow::stream::BStr>>::partial_cmp Unexecuted instantiation: <&[u8] as core::cmp::PartialOrd<winnow::stream::BStr>>::partial_cmp Unexecuted instantiation: <str as core::cmp::PartialOrd<winnow::stream::BStr>>::partial_cmp Unexecuted instantiation: <&str as core::cmp::PartialOrd<winnow::stream::BStr>>::partial_cmp |
41 | | } |
42 | | }; |
43 | | } |
44 | | |
45 | | mod bytes { |
46 | | use crate::lib::std::{cmp::Ordering, fmt, ops}; |
47 | | |
48 | | use crate::stream::Bytes; |
49 | | |
50 | | impl fmt::Display for Bytes { |
51 | | #[inline] |
52 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
53 | 0 | <Self as fmt::UpperHex>::fmt(self, f) |
54 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::fmt::Display>::fmt Unexecuted instantiation: <winnow::stream::Bytes as core::fmt::Display>::fmt |
55 | | } |
56 | | |
57 | | impl fmt::Debug for Bytes { |
58 | | #[inline] |
59 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
60 | 0 | <Self as fmt::UpperHex>::fmt(self, f) |
61 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::fmt::Debug>::fmt Unexecuted instantiation: <winnow::stream::Bytes as core::fmt::Debug>::fmt |
62 | | } |
63 | | |
64 | | impl fmt::LowerHex for Bytes { |
65 | | #[inline] |
66 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
67 | 0 | for byte in self.as_bytes() { |
68 | 0 | write!(f, "{byte:0>2x}")?; |
69 | | } |
70 | 0 | Ok(()) |
71 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::fmt::LowerHex>::fmt Unexecuted instantiation: <winnow::stream::Bytes as core::fmt::LowerHex>::fmt |
72 | | } |
73 | | |
74 | | impl fmt::UpperHex for Bytes { |
75 | | #[inline] |
76 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
77 | 0 | for (i, byte) in self.as_bytes().iter().enumerate() { |
78 | 0 | if 0 < i { |
79 | 0 | let absolute = (self.as_bytes().as_ptr() as usize) + i; |
80 | 0 | if f.alternate() && absolute != 0 && absolute % 4 == 0 { |
81 | 0 | write!(f, "_")?; |
82 | 0 | } |
83 | 0 | } |
84 | 0 | write!(f, "{byte:0>2X}")?; |
85 | | } |
86 | 0 | Ok(()) |
87 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::fmt::UpperHex>::fmt Unexecuted instantiation: <winnow::stream::Bytes as core::fmt::UpperHex>::fmt |
88 | | } |
89 | | |
90 | | impl ops::Deref for Bytes { |
91 | | type Target = [u8]; |
92 | | |
93 | | #[inline] |
94 | 0 | fn deref(&self) -> &[u8] { |
95 | 0 | self.as_bytes() |
96 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::ops::deref::Deref>::deref Unexecuted instantiation: <winnow::stream::Bytes as core::ops::deref::Deref>::deref |
97 | | } |
98 | | |
99 | | impl ops::Index<usize> for Bytes { |
100 | | type Output = u8; |
101 | | |
102 | | #[inline] |
103 | 0 | fn index(&self, idx: usize) -> &u8 { |
104 | 0 | &self.as_bytes()[idx] |
105 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<usize>>::index Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<usize>>::index |
106 | | } |
107 | | |
108 | | impl ops::Index<ops::RangeFull> for Bytes { |
109 | | type Output = Bytes; |
110 | | |
111 | | #[inline] |
112 | 0 | fn index(&self, _: ops::RangeFull) -> &Bytes { |
113 | 0 | self |
114 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeFull>>::index Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeFull>>::index |
115 | | } |
116 | | |
117 | | impl ops::Index<ops::Range<usize>> for Bytes { |
118 | | type Output = Bytes; |
119 | | |
120 | | #[inline] |
121 | 0 | fn index(&self, r: ops::Range<usize>) -> &Bytes { |
122 | 0 | Bytes::new(&self.as_bytes()[r.start..r.end]) |
123 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::Range<usize>>>::index Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::Range<usize>>>::index |
124 | | } |
125 | | |
126 | | impl ops::Index<ops::RangeInclusive<usize>> for Bytes { |
127 | | type Output = Bytes; |
128 | | |
129 | | #[inline] |
130 | 0 | fn index(&self, r: ops::RangeInclusive<usize>) -> &Bytes { |
131 | 0 | Bytes::new(&self.as_bytes()[*r.start()..=*r.end()]) |
132 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeInclusive<usize>>>::index Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeInclusive<usize>>>::index |
133 | | } |
134 | | |
135 | | impl ops::Index<ops::RangeFrom<usize>> for Bytes { |
136 | | type Output = Bytes; |
137 | | |
138 | | #[inline] |
139 | 0 | fn index(&self, r: ops::RangeFrom<usize>) -> &Bytes { |
140 | 0 | Bytes::new(&self.as_bytes()[r.start..]) |
141 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeFrom<usize>>>::index Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeFrom<usize>>>::index |
142 | | } |
143 | | |
144 | | impl ops::Index<ops::RangeTo<usize>> for Bytes { |
145 | | type Output = Bytes; |
146 | | |
147 | | #[inline] |
148 | 0 | fn index(&self, r: ops::RangeTo<usize>) -> &Bytes { |
149 | 0 | Bytes::new(&self.as_bytes()[..r.end]) |
150 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeTo<usize>>>::index Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeTo<usize>>>::index |
151 | | } |
152 | | |
153 | | impl ops::Index<ops::RangeToInclusive<usize>> for Bytes { |
154 | | type Output = Bytes; |
155 | | |
156 | | #[inline] |
157 | 0 | fn index(&self, r: ops::RangeToInclusive<usize>) -> &Bytes { |
158 | 0 | Bytes::new(&self.as_bytes()[..=r.end]) |
159 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeToInclusive<usize>>>::index Unexecuted instantiation: <winnow::stream::Bytes as core::ops::index::Index<core::ops::range::RangeToInclusive<usize>>>::index |
160 | | } |
161 | | |
162 | | impl AsRef<[u8]> for Bytes { |
163 | | #[inline] |
164 | 0 | fn as_ref(&self) -> &[u8] { |
165 | 0 | self.as_bytes() |
166 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::convert::AsRef<[u8]>>::as_ref Unexecuted instantiation: <winnow::stream::Bytes as core::convert::AsRef<[u8]>>::as_ref |
167 | | } |
168 | | |
169 | | impl AsRef<Bytes> for [u8] { |
170 | | #[inline] |
171 | 0 | fn as_ref(&self) -> &Bytes { |
172 | 0 | Bytes::new(self) |
173 | 0 | } Unexecuted instantiation: <[u8] as core::convert::AsRef<winnow::stream::Bytes>>::as_ref Unexecuted instantiation: <[u8] as core::convert::AsRef<winnow::stream::Bytes>>::as_ref |
174 | | } |
175 | | |
176 | | impl AsRef<Bytes> for str { |
177 | | #[inline] |
178 | 0 | fn as_ref(&self) -> &Bytes { |
179 | 0 | Bytes::new(self) |
180 | 0 | } Unexecuted instantiation: <str as core::convert::AsRef<winnow::stream::Bytes>>::as_ref Unexecuted instantiation: <str as core::convert::AsRef<winnow::stream::Bytes>>::as_ref |
181 | | } |
182 | | |
183 | | #[cfg(feature = "alloc")] |
184 | | impl crate::lib::std::borrow::ToOwned for Bytes { |
185 | | type Owned = crate::lib::std::vec::Vec<u8>; |
186 | | |
187 | | #[inline] |
188 | 0 | fn to_owned(&self) -> Self::Owned { |
189 | 0 | crate::lib::std::vec::Vec::from(self.as_bytes()) |
190 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as alloc::borrow::ToOwned>::to_owned Unexecuted instantiation: <winnow::stream::Bytes as alloc::borrow::ToOwned>::to_owned |
191 | | } |
192 | | |
193 | | #[cfg(feature = "alloc")] |
194 | | impl crate::lib::std::borrow::Borrow<Bytes> for crate::lib::std::vec::Vec<u8> { |
195 | | #[inline] |
196 | 0 | fn borrow(&self) -> &Bytes { |
197 | 0 | Bytes::from_bytes(self.as_slice()) |
198 | 0 | } Unexecuted instantiation: <alloc::vec::Vec<u8> as core::borrow::Borrow<winnow::stream::Bytes>>::borrow Unexecuted instantiation: <alloc::vec::Vec<u8> as core::borrow::Borrow<winnow::stream::Bytes>>::borrow |
199 | | } |
200 | | |
201 | | impl<'a> Default for &'a Bytes { |
202 | 0 | fn default() -> &'a Bytes { |
203 | 0 | Bytes::new(b"") |
204 | 0 | } Unexecuted instantiation: <&winnow::stream::Bytes as core::default::Default>::default Unexecuted instantiation: <&winnow::stream::Bytes as core::default::Default>::default |
205 | | } |
206 | | |
207 | | impl<'a> From<&'a [u8]> for &'a Bytes { |
208 | | #[inline] |
209 | 0 | fn from(s: &'a [u8]) -> &'a Bytes { |
210 | 0 | Bytes::new(s) |
211 | 0 | } Unexecuted instantiation: <&winnow::stream::Bytes as core::convert::From<&[u8]>>::from Unexecuted instantiation: <&winnow::stream::Bytes as core::convert::From<&[u8]>>::from |
212 | | } |
213 | | |
214 | | impl<'a> From<&'a Bytes> for &'a [u8] { |
215 | | #[inline] |
216 | 0 | fn from(s: &'a Bytes) -> &'a [u8] { |
217 | 0 | Bytes::as_bytes(s) |
218 | 0 | } Unexecuted instantiation: <&[u8] as core::convert::From<&winnow::stream::Bytes>>::from Unexecuted instantiation: <&[u8] as core::convert::From<&winnow::stream::Bytes>>::from |
219 | | } |
220 | | |
221 | | impl<'a> From<&'a str> for &'a Bytes { |
222 | | #[inline] |
223 | 0 | fn from(s: &'a str) -> &'a Bytes { |
224 | 0 | Bytes::new(s.as_bytes()) |
225 | 0 | } Unexecuted instantiation: <&winnow::stream::Bytes as core::convert::From<&str>>::from Unexecuted instantiation: <&winnow::stream::Bytes as core::convert::From<&str>>::from |
226 | | } |
227 | | |
228 | | impl Eq for Bytes {} |
229 | | |
230 | | impl PartialEq<Bytes> for Bytes { |
231 | | #[inline] |
232 | 0 | fn eq(&self, other: &Bytes) -> bool { |
233 | 0 | self.as_bytes() == other.as_bytes() |
234 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq>::eq Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialEq>::eq |
235 | | } |
236 | | |
237 | | impl_partial_eq!(Bytes, [u8]); |
238 | | impl_partial_eq!(Bytes, &'a [u8]); |
239 | | impl_partial_eq!(Bytes, str); |
240 | | impl_partial_eq!(Bytes, &'a str); |
241 | | |
242 | | impl PartialOrd for Bytes { |
243 | | #[inline] |
244 | 0 | fn partial_cmp(&self, other: &Bytes) -> Option<Ordering> { |
245 | 0 | Some(self.cmp(other)) |
246 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd>::partial_cmp Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::PartialOrd>::partial_cmp |
247 | | } |
248 | | |
249 | | impl Ord for Bytes { |
250 | | #[inline] |
251 | 0 | fn cmp(&self, other: &Bytes) -> Ordering { |
252 | 0 | Ord::cmp(self.as_bytes(), other.as_bytes()) |
253 | 0 | } Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::Ord>::cmp Unexecuted instantiation: <winnow::stream::Bytes as core::cmp::Ord>::cmp |
254 | | } |
255 | | |
256 | | impl_partial_ord!(Bytes, [u8]); |
257 | | impl_partial_ord!(Bytes, &'a [u8]); |
258 | | impl_partial_ord!(Bytes, str); |
259 | | impl_partial_ord!(Bytes, &'a str); |
260 | | |
261 | | #[cfg(all(test, feature = "std"))] |
262 | | mod display { |
263 | | use crate::stream::Bytes; |
264 | | |
265 | | #[test] |
266 | | fn clean() { |
267 | | assert_eq!(&format!("{}", Bytes::new(b"abc")), "616263"); |
268 | | assert_eq!(&format!("{}", Bytes::new(b"\xf0\x28\x8c\xbc")), "F0288CBC"); |
269 | | } |
270 | | } |
271 | | |
272 | | #[cfg(all(test, feature = "std"))] |
273 | | mod debug { |
274 | | use crate::stream::Bytes; |
275 | | |
276 | | #[test] |
277 | | fn test_debug() { |
278 | | assert_eq!( |
279 | | "000000206674797069736F6D0000020069736F6D69736F32617663316D70", |
280 | | format!( |
281 | | "{:?}", |
282 | | Bytes::new(b"\0\0\0 ftypisom\0\0\x02\0isomiso2avc1mp") |
283 | | ), |
284 | | ); |
285 | | } |
286 | | |
287 | | #[test] |
288 | | fn test_pretty_debug() { |
289 | | // Output can change from run-to-run |
290 | | format!( |
291 | | "{:#?}", |
292 | | Bytes::new(b"\0\0\0 ftypisom\0\0\x02\0isomiso2avc1mp") |
293 | | ); |
294 | | } |
295 | | |
296 | | #[test] |
297 | | fn test_sliced() { |
298 | | // Output can change from run-to-run |
299 | | let total = Bytes::new(b"12345678901234567890"); |
300 | | format!("{total:#?}"); |
301 | | format!("{:#?}", &total[1..]); |
302 | | format!("{:#?}", &total[10..]); |
303 | | } |
304 | | } |
305 | | } |
306 | | |
307 | | mod bstr { |
308 | | use crate::lib::std::{cmp::Ordering, fmt, ops}; |
309 | | |
310 | | use crate::stream::BStr; |
311 | | |
312 | | #[cfg(feature = "alloc")] |
313 | | impl fmt::Display for BStr { |
314 | | #[inline] |
315 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
316 | 0 | crate::lib::std::string::String::from_utf8_lossy(self.as_bytes()).fmt(f) |
317 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::fmt::Display>::fmt Unexecuted instantiation: <winnow::stream::BStr as core::fmt::Display>::fmt |
318 | | } |
319 | | |
320 | | impl fmt::Debug for BStr { |
321 | | #[inline] |
322 | 0 | fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
323 | 0 | if !f.alternate() { |
324 | 0 | write!(f, "\"")?; |
325 | 0 | } |
326 | 0 | for byte in self.as_bytes() { |
327 | 0 | let c = *byte as char; |
328 | 0 | write!(f, "{}", c.escape_debug())?; |
329 | | } |
330 | 0 | if !f.alternate() { |
331 | 0 | write!(f, "\"")?; |
332 | 0 | } |
333 | 0 | Ok(()) |
334 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::fmt::Debug>::fmt Unexecuted instantiation: <winnow::stream::BStr as core::fmt::Debug>::fmt |
335 | | } |
336 | | |
337 | | impl ops::Deref for BStr { |
338 | | type Target = [u8]; |
339 | | |
340 | | #[inline] |
341 | 0 | fn deref(&self) -> &[u8] { |
342 | 0 | self.as_bytes() |
343 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::ops::deref::Deref>::deref Unexecuted instantiation: <winnow::stream::BStr as core::ops::deref::Deref>::deref |
344 | | } |
345 | | |
346 | | impl ops::Index<usize> for BStr { |
347 | | type Output = u8; |
348 | | |
349 | | #[inline] |
350 | 0 | fn index(&self, idx: usize) -> &u8 { |
351 | 0 | &self.as_bytes()[idx] |
352 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<usize>>::index Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<usize>>::index |
353 | | } |
354 | | |
355 | | impl ops::Index<ops::RangeFull> for BStr { |
356 | | type Output = BStr; |
357 | | |
358 | | #[inline] |
359 | 0 | fn index(&self, _: ops::RangeFull) -> &BStr { |
360 | 0 | self |
361 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeFull>>::index Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeFull>>::index |
362 | | } |
363 | | |
364 | | impl ops::Index<ops::Range<usize>> for BStr { |
365 | | type Output = BStr; |
366 | | |
367 | | #[inline] |
368 | 0 | fn index(&self, r: ops::Range<usize>) -> &BStr { |
369 | 0 | BStr::new(&self.as_bytes()[r.start..r.end]) |
370 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::Range<usize>>>::index Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::Range<usize>>>::index |
371 | | } |
372 | | |
373 | | impl ops::Index<ops::RangeInclusive<usize>> for BStr { |
374 | | type Output = BStr; |
375 | | |
376 | | #[inline] |
377 | 0 | fn index(&self, r: ops::RangeInclusive<usize>) -> &BStr { |
378 | 0 | BStr::new(&self.as_bytes()[*r.start()..=*r.end()]) |
379 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeInclusive<usize>>>::index Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeInclusive<usize>>>::index |
380 | | } |
381 | | |
382 | | impl ops::Index<ops::RangeFrom<usize>> for BStr { |
383 | | type Output = BStr; |
384 | | |
385 | | #[inline] |
386 | 0 | fn index(&self, r: ops::RangeFrom<usize>) -> &BStr { |
387 | 0 | BStr::new(&self.as_bytes()[r.start..]) |
388 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeFrom<usize>>>::index Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeFrom<usize>>>::index |
389 | | } |
390 | | |
391 | | impl ops::Index<ops::RangeTo<usize>> for BStr { |
392 | | type Output = BStr; |
393 | | |
394 | | #[inline] |
395 | 0 | fn index(&self, r: ops::RangeTo<usize>) -> &BStr { |
396 | 0 | BStr::new(&self.as_bytes()[..r.end]) |
397 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeTo<usize>>>::index Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeTo<usize>>>::index |
398 | | } |
399 | | |
400 | | impl ops::Index<ops::RangeToInclusive<usize>> for BStr { |
401 | | type Output = BStr; |
402 | | |
403 | | #[inline] |
404 | 0 | fn index(&self, r: ops::RangeToInclusive<usize>) -> &BStr { |
405 | 0 | BStr::new(&self.as_bytes()[..=r.end]) |
406 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeToInclusive<usize>>>::index Unexecuted instantiation: <winnow::stream::BStr as core::ops::index::Index<core::ops::range::RangeToInclusive<usize>>>::index |
407 | | } |
408 | | |
409 | | impl AsRef<[u8]> for BStr { |
410 | | #[inline] |
411 | 0 | fn as_ref(&self) -> &[u8] { |
412 | 0 | self.as_bytes() |
413 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::convert::AsRef<[u8]>>::as_ref Unexecuted instantiation: <winnow::stream::BStr as core::convert::AsRef<[u8]>>::as_ref |
414 | | } |
415 | | |
416 | | impl AsRef<BStr> for [u8] { |
417 | | #[inline] |
418 | 0 | fn as_ref(&self) -> &BStr { |
419 | 0 | BStr::new(self) |
420 | 0 | } Unexecuted instantiation: <[u8] as core::convert::AsRef<winnow::stream::BStr>>::as_ref Unexecuted instantiation: <[u8] as core::convert::AsRef<winnow::stream::BStr>>::as_ref |
421 | | } |
422 | | |
423 | | impl AsRef<BStr> for str { |
424 | | #[inline] |
425 | 0 | fn as_ref(&self) -> &BStr { |
426 | 0 | BStr::new(self) |
427 | 0 | } Unexecuted instantiation: <str as core::convert::AsRef<winnow::stream::BStr>>::as_ref Unexecuted instantiation: <str as core::convert::AsRef<winnow::stream::BStr>>::as_ref |
428 | | } |
429 | | |
430 | | #[cfg(feature = "alloc")] |
431 | | impl crate::lib::std::borrow::ToOwned for BStr { |
432 | | type Owned = crate::lib::std::vec::Vec<u8>; |
433 | | |
434 | | #[inline] |
435 | 0 | fn to_owned(&self) -> Self::Owned { |
436 | 0 | crate::lib::std::vec::Vec::from(self.as_bytes()) |
437 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as alloc::borrow::ToOwned>::to_owned Unexecuted instantiation: <winnow::stream::BStr as alloc::borrow::ToOwned>::to_owned |
438 | | } |
439 | | |
440 | | #[cfg(feature = "alloc")] |
441 | | impl crate::lib::std::borrow::Borrow<BStr> for crate::lib::std::vec::Vec<u8> { |
442 | | #[inline] |
443 | 0 | fn borrow(&self) -> &BStr { |
444 | 0 | BStr::from_bytes(self.as_slice()) |
445 | 0 | } Unexecuted instantiation: <alloc::vec::Vec<u8> as core::borrow::Borrow<winnow::stream::BStr>>::borrow Unexecuted instantiation: <alloc::vec::Vec<u8> as core::borrow::Borrow<winnow::stream::BStr>>::borrow |
446 | | } |
447 | | |
448 | | impl<'a> Default for &'a BStr { |
449 | 0 | fn default() -> &'a BStr { |
450 | 0 | BStr::new(b"") |
451 | 0 | } Unexecuted instantiation: <&winnow::stream::BStr as core::default::Default>::default Unexecuted instantiation: <&winnow::stream::BStr as core::default::Default>::default |
452 | | } |
453 | | |
454 | | impl<'a> From<&'a [u8]> for &'a BStr { |
455 | | #[inline] |
456 | 0 | fn from(s: &'a [u8]) -> &'a BStr { |
457 | 0 | BStr::new(s) |
458 | 0 | } Unexecuted instantiation: <&winnow::stream::BStr as core::convert::From<&[u8]>>::from Unexecuted instantiation: <&winnow::stream::BStr as core::convert::From<&[u8]>>::from |
459 | | } |
460 | | |
461 | | impl<'a> From<&'a BStr> for &'a [u8] { |
462 | | #[inline] |
463 | 0 | fn from(s: &'a BStr) -> &'a [u8] { |
464 | 0 | BStr::as_bytes(s) |
465 | 0 | } Unexecuted instantiation: <&[u8] as core::convert::From<&winnow::stream::BStr>>::from Unexecuted instantiation: <&[u8] as core::convert::From<&winnow::stream::BStr>>::from |
466 | | } |
467 | | |
468 | | impl<'a> From<&'a str> for &'a BStr { |
469 | | #[inline] |
470 | 0 | fn from(s: &'a str) -> &'a BStr { |
471 | 0 | BStr::new(s.as_bytes()) |
472 | 0 | } Unexecuted instantiation: <&winnow::stream::BStr as core::convert::From<&str>>::from Unexecuted instantiation: <&winnow::stream::BStr as core::convert::From<&str>>::from |
473 | | } |
474 | | |
475 | | impl Eq for BStr {} |
476 | | |
477 | | impl PartialEq<BStr> for BStr { |
478 | | #[inline] |
479 | 0 | fn eq(&self, other: &BStr) -> bool { |
480 | 0 | self.as_bytes() == other.as_bytes() |
481 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq>::eq Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialEq>::eq |
482 | | } |
483 | | |
484 | | impl_partial_eq!(BStr, [u8]); |
485 | | impl_partial_eq!(BStr, &'a [u8]); |
486 | | impl_partial_eq!(BStr, str); |
487 | | impl_partial_eq!(BStr, &'a str); |
488 | | |
489 | | impl PartialOrd for BStr { |
490 | | #[inline] |
491 | 0 | fn partial_cmp(&self, other: &BStr) -> Option<Ordering> { |
492 | 0 | Some(self.cmp(other)) |
493 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd>::partial_cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::PartialOrd>::partial_cmp |
494 | | } |
495 | | |
496 | | impl Ord for BStr { |
497 | | #[inline] |
498 | 0 | fn cmp(&self, other: &BStr) -> Ordering { |
499 | 0 | Ord::cmp(self.as_bytes(), other.as_bytes()) |
500 | 0 | } Unexecuted instantiation: <winnow::stream::BStr as core::cmp::Ord>::cmp Unexecuted instantiation: <winnow::stream::BStr as core::cmp::Ord>::cmp |
501 | | } |
502 | | |
503 | | impl_partial_ord!(BStr, [u8]); |
504 | | impl_partial_ord!(BStr, &'a [u8]); |
505 | | impl_partial_ord!(BStr, str); |
506 | | impl_partial_ord!(BStr, &'a str); |
507 | | |
508 | | #[cfg(all(test, feature = "std"))] |
509 | | mod display { |
510 | | use crate::stream::BStr; |
511 | | |
512 | | #[test] |
513 | | fn clean() { |
514 | | assert_eq!(&format!("{}", BStr::new(b"abc")), "abc"); |
515 | | assert_eq!(&format!("{}", BStr::new(b"\xf0\x28\x8c\xbc")), "�(��"); |
516 | | } |
517 | | } |
518 | | |
519 | | #[cfg(all(test, feature = "std"))] |
520 | | mod debug { |
521 | | use crate::stream::BStr; |
522 | | |
523 | | #[test] |
524 | | fn test_debug() { |
525 | | assert_eq!(&format!("{:?}", BStr::new(b"abc")), "\"abc\""); |
526 | | |
527 | | assert_eq!( |
528 | | "\"\\0\\0\\0 ftypisom\\0\\0\\u{2}\\0isomiso2avc1mp\"", |
529 | | format!( |
530 | | "{:?}", |
531 | | BStr::new(b"\0\0\0 ftypisom\0\0\x02\0isomiso2avc1mp") |
532 | | ), |
533 | | ); |
534 | | } |
535 | | |
536 | | #[test] |
537 | | fn test_pretty_debug() { |
538 | | assert_eq!(&format!("{:#?}", BStr::new(b"abc")), "abc"); |
539 | | } |
540 | | } |
541 | | } |