Propagate errors in Input::packets().

This commit is contained in:
Nebojsa Sabovic
2023-04-15 22:44:12 +02:00
committed by Josh Holmer
parent fa2b8d13ad
commit 05bad6e9e0
5 changed files with 14 additions and 16 deletions

View File

@ -159,24 +159,22 @@ impl<'a> PacketIter<'a> {
}
impl<'a> Iterator for PacketIter<'a> {
type Item = (Stream<'a>, Packet);
type Item = Result<(Stream<'a>, Packet), Error>;
fn next(&mut self) -> Option<<Self as Iterator>::Item> {
let mut packet = Packet::empty();
loop {
match packet.read(self.context) {
Ok(..) => unsafe {
return Some((
Stream::wrap(mem::transmute_copy(&self.context), packet.stream()),
packet,
));
},
match packet.read(self.context) {
Ok(..) => unsafe {
Some(Ok((
Stream::wrap(mem::transmute_copy(&self.context), packet.stream()),
packet,
)))
},
Err(Error::Eof) => return None,
Err(Error::Eof) => None,
Err(..) => (),
}
Err(e) => Some(Err(e)),
}
}
}