Skip to content

Commit aebdbf5

Browse files
committed
refactor: simplify expressions
1 parent dedb17b commit aebdbf5

File tree

2 files changed

+9
-18
lines changed

2 files changed

+9
-18
lines changed

src/codec/gzip/decoder.rs

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -166,19 +166,13 @@ impl Decode for GzipDecoder {
166166
output: &mut PartialBuffer<impl AsRef<[u8]> + AsMut<[u8]>>,
167167
) -> Result<bool> {
168168
match &mut self.state {
169-
State::Done => return Ok(true),
170-
State::Header(parser) => {
171-
// In this case, the input was an empty gzip. Exit successfully with an empty gzip.
172-
if parser.has_no_content() {
173-
return Ok(true);
174-
}
175-
}
176-
_ => {}
169+
State::Done => Ok(true),
170+
// In this case, the input was an empty gzip. Exit successfully with an empty gzip.
171+
State::Header(parser) if parser.has_no_content() => Ok(true),
172+
_ => Err(Error::new(
173+
ErrorKind::UnexpectedEof,
174+
"unexpected end of file",
175+
)),
177176
}
178-
179-
Err(Error::new(
180-
ErrorKind::UnexpectedEof,
181-
"unexpected end of file",
182-
))
183177
}
184178
}

src/codec/gzip/header.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::util::PartialBuffer;
2-
use std::io;
2+
use std::{io, iter};
33

44
#[derive(Debug, Default)]
55
struct Flags {
@@ -163,9 +163,6 @@ impl Parser {
163163
}
164164

165165
pub(super) fn has_no_content(&self) -> bool {
166-
match &self.state {
167-
State::Fixed(data) => data.buffer().iter().all(|&b| b == 0),
168-
_ => false,
169-
}
166+
matches!(&self.state, State::Fixed(data) if data.buffer().iter().all(|&b| b == 0))
170167
}
171168
}

0 commit comments

Comments
 (0)