/// Iterator over the bytes contained by the buffer. /// /// # Examples /// /// Basic usage: /// /// ``` /// use bytes::Bytes; /// /// let buf = Bytes::from(&b"abc"[..]); /// let mut iter = buf.into_iter(); /// /// assert_eq!(iter.next(), Some(b'a')); /// assert_eq!(iter.next(), Some(b'b')); /// assert_eq!(iter.next(), Some(b'c')); /// assert_eq!(iter.next(), None); /// ``` /// /// [`iter`]: trait.Buf.html#method.iter /// [`Buf`]: trait.Buf.html #[derive(Debug)] pubstruct IntoIter<T> {
inner: T,
}
impl<T> IntoIter<T> { /// Creates an iterator over the bytes contained by the buffer. /// /// # Examples /// /// ``` /// use bytes::Bytes; /// /// let buf = Bytes::from_static(b"abc"); /// let mut iter = buf.into_iter(); /// /// assert_eq!(iter.next(), Some(b'a')); /// assert_eq!(iter.next(), Some(b'b')); /// assert_eq!(iter.next(), Some(b'c')); /// assert_eq!(iter.next(), None); /// ``` pubfn new(inner: T) -> IntoIter<T> {
IntoIter { inner }
}
/// Consumes this `IntoIter`, returning the underlying value. /// /// # Examples /// /// ```rust /// use bytes::{Buf, Bytes}; /// /// let buf = Bytes::from(&b"abc"[..]); /// let mut iter = buf.into_iter(); /// /// assert_eq!(iter.next(), Some(b'a')); /// /// let buf = iter.into_inner(); /// assert_eq!(2, buf.remaining()); /// ``` pubfn into_inner(self) -> T { self.inner
}
/// Gets a reference to the underlying `Buf`. /// /// It is inadvisable to directly read from the underlying `Buf`. /// /// # Examples /// /// ```rust /// use bytes::{Buf, Bytes}; /// /// let buf = Bytes::from(&b"abc"[..]); /// let mut iter = buf.into_iter(); /// /// assert_eq!(iter.next(), Some(b'a')); /// /// assert_eq!(2, iter.get_ref().remaining()); /// ``` pubfn get_ref(&self) -> &T {
&self.inner
}
/// Gets a mutable reference to the underlying `Buf`. /// /// It is inadvisable to directly read from the underlying `Buf`. /// /// # Examples /// /// ```rust /// use bytes::{Buf, BytesMut}; /// /// let buf = BytesMut::from(&b"abc"[..]); /// let mut iter = buf.into_iter(); /// /// assert_eq!(iter.next(), Some(b'a')); /// /// iter.get_mut().advance(1); /// /// assert_eq!(iter.next(), Some(b'c')); /// ``` pubfn get_mut(&mutself) -> &mut T {
&mutself.inner
}
}
impl<T: Buf> Iterator for IntoIter<T> { type Item = u8;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.