diff --git a/src/ext_slice.rs b/src/ext_slice.rs index f42d1a7..fa08190 100644 --- a/src/ext_slice.rs +++ b/src/ext_slice.rs @@ -5,12 +5,7 @@ use std::ffi::OsStr; #[cfg(feature = "std")] use std::path::Path; -use core::cmp; -use core::ops; -use core::ptr; -use core::slice; -use core::str; - +use core::{cmp, iter, ops, ptr, slice, str}; use memchr::{memchr, memrchr}; use ascii; @@ -3255,6 +3250,16 @@ pub struct Bytes<'a> { it: slice::Iter<'a, u8>, } +impl<'a> Bytes<'a> { + /// Views the remaining underlying data as a subslice of the original data. + /// This has the same lifetime as the original slice, + /// and so the iterator can continue to be used while this exists. + #[inline] + pub fn as_slice(&self) -> &'a [u8] { + self.it.as_slice() + } +} + impl<'a> Iterator for Bytes<'a> { type Item = u8; @@ -3262,6 +3267,11 @@ impl<'a> Iterator for Bytes<'a> { fn next(&mut self) -> Option { self.it.next().map(|&b| b) } + + #[inline] + fn size_hint(&self) -> (usize, Option) { + self.it.size_hint() + } } impl<'a> DoubleEndedIterator for Bytes<'a> { @@ -3278,6 +3288,8 @@ impl<'a> ExactSizeIterator for Bytes<'a> { } } +impl<'a> iter::FusedIterator for Bytes<'a> {} + /// An iterator over the fields in a byte string, separated by whitespace. /// /// This iterator splits on contiguous runs of whitespace, such that the fields