From fd547919e3ed435261d9c49539c6e535e33a8e16 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Sun, 4 Jul 2021 10:10:59 +0900 Subject: [PATCH 1/2] refactor(header): use `matches!` --- src/header.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/header.rs b/src/header.rs index 5e4c512..6362c04 100644 --- a/src/header.rs +++ b/src/header.rs @@ -223,7 +223,7 @@ pub enum Class { impl Class { pub fn is_none(&self) -> bool { - if let Class::None = *self { true } else { false } + matches!(*self, Class::None) } } @@ -261,7 +261,7 @@ pub enum Data { impl Data { pub fn is_none(&self) -> bool { - if let Data::None = *self { true } else { false } + matches!(*self, Data::None) } } @@ -297,11 +297,7 @@ pub enum Version { impl Version { pub fn is_none(&self) -> bool { - if let Version::None = *self { - true - } else { - false - } + matches!(*self, Version::None) } } From b1070f68c9549a82fe00fdec6c3e2f52e760e3a6 Mon Sep 17 00:00:00 2001 From: Hiroki Tokunaga Date: Tue, 6 Jul 2021 13:44:39 +0900 Subject: [PATCH 2/2] refactor: use `Result::map` --- src/lib.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 945b959..44611fc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,11 +47,7 @@ pub struct ElfFile<'a> { impl<'a> ElfFile<'a> { pub fn new(input: &'a [u8]) -> Result, &'static str> { - let header = header::parse_header(input)?; - Ok(ElfFile { - input, - header, - }) + header::parse_header(input).map(|header| ElfFile {input, header}) } pub fn section_header(&self, index: u16) -> Result, &'static str> {