//! Extensions use bytes::Buf; use std::io::BufRead; #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct BufIter(B); pub trait BufIterExt { fn chunks_iter(self) -> BufIter; } impl Iterator for BufIter { type Item = bytes::Bytes; fn next(&mut self) -> Option { if self.0.has_remaining() { Some(self.0.copy_to_bytes(self.0.chunk().len())) } else { None } } } impl BufIterExt for B { fn chunks_iter(self) -> BufIter { BufIter(self) } } /* pub struct BufReadIter(usize, B); pub trait BufReadExt { fn chunks_iter(self, sz: usize) -> BufReadIter; } impl Iterator for BufReadIter { type Item = bytes::Bytes; fn next(&mut self) -> Option { self.1.read_exact(buf) } } */