Implement iterator adapter for Buf

This commit is contained in:
Carl Lerche
2017-03-01 10:03:28 -08:00
parent 4f8c565111
commit 8fec8a92ad
4 changed files with 173 additions and 2 deletions
+38 -1
View File
@@ -1,4 +1,5 @@
use {IntoBuf, BufMut};
use {IntoBuf, Buf, BufMut};
use buf::Iter;
use std::{cmp, fmt, mem, hash, ops, slice, ptr, usize};
use std::borrow::Borrow;
@@ -733,6 +734,24 @@ impl Borrow<[u8]> for Bytes {
}
}
impl IntoIterator for Bytes {
type Item = u8;
type IntoIter = Iter<Cursor<Bytes>>;
fn into_iter(self) -> Self::IntoIter {
self.into_buf().iter()
}
}
impl<'a> IntoIterator for &'a Bytes {
type Item = u8;
type IntoIter = Iter<Cursor<&'a Bytes>>;
fn into_iter(self) -> Self::IntoIter {
self.into_buf().iter()
}
}
/*
*
* ===== BytesMut =====
@@ -1286,6 +1305,24 @@ impl Clone for BytesMut {
}
}
impl IntoIterator for BytesMut {
type Item = u8;
type IntoIter = Iter<Cursor<BytesMut>>;
fn into_iter(self) -> Self::IntoIter {
self.into_buf().iter()
}
}
impl<'a> IntoIterator for &'a BytesMut {
type Item = u8;
type IntoIter = Iter<Cursor<&'a BytesMut>>;
fn into_iter(self) -> Self::IntoIter {
self.into_buf().iter()
}
}
/*
*
* ===== Inner =====