You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
852 B
50 lines
852 B
//! Extensions
|
|
use bytes::Buf;
|
|
use std::io::BufRead;
|
|
|
|
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
|
pub struct BufIter<B: ?Sized>(B);
|
|
|
|
pub trait BufIterExt
|
|
{
|
|
fn chunks_iter(self) -> BufIter<Self>;
|
|
}
|
|
|
|
impl<T: ?Sized + Buf> Iterator for BufIter<T>
|
|
{
|
|
type Item = bytes::Bytes;
|
|
fn next(&mut self) -> Option<Self::Item>
|
|
{
|
|
if self.0.has_remaining() {
|
|
Some(self.0.copy_to_bytes(self.0.chunk().len()))
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
}
|
|
|
|
impl<B: Buf> BufIterExt for B
|
|
{
|
|
fn chunks_iter(self) -> BufIter<Self> {
|
|
BufIter(self)
|
|
}
|
|
}
|
|
|
|
/*
|
|
pub struct BufReadIter<B: ?Sized>(usize, B);
|
|
|
|
pub trait BufReadExt
|
|
{
|
|
fn chunks_iter(self, sz: usize) -> BufReadIter<Self>;
|
|
}
|
|
|
|
impl<B: ?Sized + BufRead> Iterator for BufReadIter<B>
|
|
{
|
|
type Item = bytes::Bytes;
|
|
fn next(&mut self) -> Option<Self::Item>
|
|
{
|
|
self.1.read_exact(buf)
|
|
}
|
|
}
|
|
*/
|