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.

46 lines
610 B

4 years ago
use std::{
io::{
Read,
},
};
pub struct ByteIter<F: Read>
(F, [u8; 1]);
4 years ago
impl<T> Iterator for ByteIter<T>
where T: Read
4 years ago
{
type Item = u8;
4 years ago
fn next(&mut self) -> Option<Self::Item>
{
if let Ok(read) = self.0.read(&mut self.1[..])
4 years ago
{
if read < 1 {
4 years ago
None
} else {
Some(self.1[0])
4 years ago
}
} else {
None
}
}
}
impl<T> ByteIter<T>
where T: Read
4 years ago
{
fn new(stream: T) -> Self {
Self(stream, [0u8; 1])
4 years ago
}
}
pub trait ByteIterExt: Read + Sized
4 years ago
{
fn into_byte_iter(self) -> ByteIter<Self>
4 years ago
{
ByteIter::new(self)
4 years ago
}
}
impl<T: Read> ByteIterExt for T{}