@@ -86,7 +86,7 @@ impl From<OptionZBytes> for Option<ZBytes> {
86
86
}
87
87
}
88
88
89
- /// Trait to encode a type `T` into a [`Value `].
89
+ /// Trait to encode a type `T` into a [`ZBytes `].
90
90
pub trait Serialize < T > {
91
91
type Output ;
92
92
@@ -345,8 +345,8 @@ impl ZBytes {
345
345
/// assert_eq!(buf1.as_slice(), iter.next().unwrap());
346
346
/// assert_eq!(buf2.as_slice(), iter.next().unwrap());
347
347
/// ```
348
- pub fn slices ( & self ) -> impl Iterator < Item = & [ u8 ] > {
349
- self . 0 . slices ( )
348
+ pub fn slices ( & self ) -> ZBytesSliceIterator < ' _ > {
349
+ ZBytesSliceIterator ( self . 0 . slices ( ) )
350
350
}
351
351
352
352
/// Serialize an object of type `T` as a [`ZBytes`] using the [`ZSerde`].
@@ -649,6 +649,23 @@ impl std::io::Write for ZBytesWriter<'_> {
649
649
}
650
650
}
651
651
652
+ /// An iterator that implements [`std::iter::Iterator`] trait to iterate on [`&[u8]`].
653
+ #[ repr( transparent) ]
654
+ #[ derive( Debug ) ]
655
+ pub struct ZBytesSliceIterator < ' a > ( ZBytesSliceIteratorInner < ' a > ) ;
656
+
657
+ // Typedef to make clippy happy about complex type. Encapsulate inner `ZBufSliceOperator`.
658
+ type ZBytesSliceIteratorInner < ' a > =
659
+ std:: iter:: Map < core:: slice:: Iter < ' a , ZSlice > , fn ( & ' a ZSlice ) -> & ' a [ u8 ] > ;
660
+
661
+ impl < ' a > Iterator for ZBytesSliceIterator < ' a > {
662
+ type Item = & ' a [ u8 ] ;
663
+
664
+ fn next ( & mut self ) -> Option < Self :: Item > {
665
+ self . 0 . next ( )
666
+ }
667
+ }
668
+
652
669
/// An iterator that implements [`std::iter::Iterator`] trait to iterate on values `T` in a [`ZBytes`].
653
670
/// Note that [`ZBytes`] contains a serialized version of `T` and iterating over a [`ZBytes`] performs lazy deserialization.
654
671
#[ repr( transparent) ]
0 commit comments