We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 95797e9 + fd32b9a commit 3e12496Copy full SHA for 3e12496
CHANGELOG.md
@@ -96,6 +96,7 @@
96
removed the corresponding task from the inventory
97
- implemented `bytes::Buf` for `Bytes` and `From<Bytes>` for `bytes::Bytes` for
98
seamless integration with Tokio and other libraries
99
+- implemented `ExactSizeIterator` and `FusedIterator` for `BytesIterOffsets`
100
101
## 0.19.3 - 2025-05-30
102
- implemented `Error` for `ViewError`
INVENTORY.md
@@ -5,7 +5,6 @@
5
6
## Desired Functionality
7
- Add Kani proofs for winnow view helpers.
8
-- Implement `ExactSizeIterator` or `FusedIterator` for `BytesIterOffsets` to simplify iteration.
9
10
## Discovered Issues
11
- None at the moment.
src/tests.rs
@@ -281,6 +281,31 @@ fn test_winnow_stream_take() {
281
assert_eq!(input.as_bytes(), [3u8, 4].as_ref());
282
}
283
284
+#[cfg(feature = "winnow")]
285
+#[test]
286
+fn test_iter_offsets_traits() {
287
+ use std::iter::{ExactSizeIterator, FusedIterator};
288
+ use winnow::stream::Stream;
289
+
290
+ fn assert_traits<I: ExactSizeIterator + FusedIterator>(iter: I) -> I {
291
+ iter
292
+ }
293
294
+ let bytes = Bytes::from(vec![1u8, 2, 3, 4]);
295
+ let mut iter = assert_traits(Stream::iter_offsets(&bytes));
296
+ assert_eq!(iter.len(), 4);
297
+ assert_eq!(iter.size_hint(), (4, Some(4)));
298
299
+ for (i, (offset, byte)) in (&mut iter).enumerate() {
300
+ assert_eq!(offset, i);
301
+ assert_eq!(byte, bytes.as_ref()[i]);
302
303
304
+ assert_eq!(iter.len(), 0);
305
+ assert_eq!(iter.next(), None);
306
307
+}
308
309
#[cfg(all(feature = "winnow", feature = "zerocopy"))]
310
#[test]
311
fn test_winnow_view_parser() {
src/winnow.rs
@@ -33,8 +33,21 @@ impl Iterator for BytesIterOffsets {
33
self.offset += 1;
34
Some((offset, token))
35
36
37
+ fn size_hint(&self) -> (usize, Option<usize>) {
38
+ let len = self.bytes.as_slice().len();
39
+ (len, Some(len))
40
41
42
43
+impl ExactSizeIterator for BytesIterOffsets {
44
+ fn len(&self) -> usize {
45
+ self.bytes.as_slice().len()
46
47
48
49
+impl std::iter::FusedIterator for BytesIterOffsets {}
50
51
impl SliceLen for Bytes {
52
#[inline(always)]
53
fn slice_len(&self) -> usize {
0 commit comments