From 4f36a27c32c7866c6be8abf3dad76a97c0872674 Mon Sep 17 00:00:00 2001 From: Benjamin Richner Date: Tue, 23 Jun 2020 21:20:30 +0200 Subject: [PATCH] Use matcher clause instead of clumsy if expressions --- src/read.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/read.rs b/src/read.rs index f89bd311..f2a927c6 100644 --- a/src/read.rs +++ b/src/read.rs @@ -396,14 +396,11 @@ impl ZipArchive { } let data = &mut self.files[file_number]; - if password == None { - if data.encrypted { - return Err(ZipError::PasswordRequired); - } - } else if !data.encrypted { - //Password supplied, but none needed! Discard. - password = None; - } + match (password, data.encrypted) { + (None, true) => return Err(ZipError::PasswordRequired), + (Some(_), false) => password = None, //Password supplied, but none needed! Discard. + _ => {} + } // Parse local header self.reader.seek(io::SeekFrom::Start(data.header_start))?;