From f5f04ea5e3872c19ec6700f47967f2c517098211 Mon Sep 17 00:00:00 2001 From: Damian Poddebniak Date: Mon, 22 Feb 2021 16:46:46 +0100 Subject: [PATCH] Thanks Clippy! --- src/parse/address.rs | 5 +---- src/parse/command.rs | 15 +++------------ src/parse/imf.rs | 15 +++------------ src/parse/replies.rs | 15 ++++++--------- src/parse/response.rs | 12 +++--------- 5 files changed, 16 insertions(+), 46 deletions(-) diff --git a/src/parse/address.rs b/src/parse/address.rs index a2b2628..2f9ed3b 100644 --- a/src/parse/address.rs +++ b/src/parse/address.rs @@ -54,10 +54,7 @@ pub fn Standardized_tag(input: &[u8]) -> IResult<&[u8], &[u8]> { /// /// dcontent = %d33-90 / %d94-126 pub fn is_dcontent(byte: u8) -> bool { - match byte { - 33..=90 | 94..=126 => true, - _ => false, - } + matches!(byte, 33..=90 | 94..=126) } /// Representing a decimal integer value in the range 0 through 255 diff --git a/src/parse/command.rs b/src/parse/command.rs index ab6d833..b4178cf 100644 --- a/src/parse/command.rs +++ b/src/parse/command.rs @@ -354,10 +354,7 @@ pub fn esmtp_keyword(input: &[u8]) -> IResult<&[u8], &[u8]> { /// esmtp-value = 1*(%d33-60 / %d62-126) pub fn esmtp_value(input: &[u8]) -> IResult<&[u8], &[u8]> { fn is_value_character(byte: u8) -> bool { - match byte { - 33..=60 | 62..=126 => true, - _ => false, - } + matches!(byte, 33..=60 | 62..=126) } take_while1(is_value_character)(input) @@ -494,10 +491,7 @@ pub fn QcontentSMTP(input: &[u8]) -> IResult<&[u8], &[u8]> { /// quoted-pairSMTP = %d92 %d32-126 pub fn quoted_pairSMTP(input: &[u8]) -> IResult<&[u8], &[u8]> { fn is_ascii_bs_or_sp(byte: u8) -> bool { - match byte { - 32..=126 => true, - _ => false, - } + matches!(byte, 32..=126) } let parser = tuple((tag("\\"), take_while_m_n(1, 1, is_ascii_bs_or_sp))); @@ -512,10 +506,7 @@ pub fn quoted_pairSMTP(input: &[u8]) -> IResult<&[u8], &[u8]> { /// /// qtextSMTP = %d32-33 / %d35-91 / %d93-126 pub fn is_qtextSMTP(byte: u8) -> bool { - match byte { - 32..=33 | 35..=91 | 93..=126 => true, - _ => false, - } + matches!(byte, 32..=33 | 35..=91 | 93..=126) } /// String = Atom / Quoted-string diff --git a/src/parse/imf.rs b/src/parse/imf.rs index 3d417c8..7c810e6 100644 --- a/src/parse/imf.rs +++ b/src/parse/imf.rs @@ -421,17 +421,11 @@ pub mod addr_spec { /// dtext = %d33-90 / %d94-126 / obs-dtext pub fn dtext(input: &[u8]) -> IResult<&[u8], &[u8]> { fn is_a(byte: u8) -> bool { - match byte { - 33..=90 => true, - _ => false, - } + matches!(byte, 33..=90) } fn is_b(byte: u8) -> bool { - match byte { - 94..=126 => true, - _ => false, - } + matches!(byte, 94..=126) } let parser = alt(( @@ -540,10 +534,7 @@ pub mod obsolete { /// /// obs-NO-WS-CTL = %d1-8 / %d11 / %d12 / %d14-31 / %d127 pub fn is_obs_NO_WS_CTL(byte: u8) -> bool { - match byte { - 1..=8 | 11 | 12 | 14..=31 | 127 => true, - _ => false, - } + matches!(byte, 1..=8 | 11 | 12 | 14..=31 | 127) } /// obs-qtext = obs-NO-WS-CTL diff --git a/src/parse/replies.rs b/src/parse/replies.rs index efe5383..e265f20 100644 --- a/src/parse/replies.rs +++ b/src/parse/replies.rs @@ -31,7 +31,7 @@ pub fn Greeting(input: &[u8]) -> IResult<&[u8], GreetingType> { domain: domain.to_owned(), text: maybe_text .map(|str| str.to_string()) - .unwrap_or("".to_string()), + .unwrap_or_else(|| "".to_string()), }, ), map( @@ -50,18 +50,18 @@ pub fn Greeting(input: &[u8]) -> IResult<&[u8], GreetingType> { text: { let mut res = maybe_text .map(|str| format!("{}\n", str)) - .unwrap_or("\n".to_string()); + .unwrap_or_else(|| "\n".to_string()); for text in more_text { let text = text .map(|str| format!("{}\n", str)) - .unwrap_or("\n".to_string()); + .unwrap_or_else(|| "\n".to_string()); res.push_str(&text); } let text = moar_text - .map(|str| format!("{}", str)) - .unwrap_or("".to_string()); + .map(|str| str.to_string()) + .unwrap_or_else(|| "".to_string()); res.push_str(&text); res @@ -80,10 +80,7 @@ pub fn Greeting(input: &[u8]) -> IResult<&[u8], GreetingType> { /// textstring = 1*(%d09 / %d32-126) pub fn textstring(input: &[u8]) -> IResult<&[u8], &str> { fn is_value(byte: u8) -> bool { - match byte { - 9 | 32..=126 => true, - _ => false, - } + matches!(byte, 9 | 32..=126) } let (remaining, parsed) = map_res(take_while1(is_value), std::str::from_utf8)(input)?; diff --git a/src/parse/response.rs b/src/parse/response.rs index 91b43e4..3793df4 100644 --- a/src/parse/response.rs +++ b/src/parse/response.rs @@ -73,10 +73,7 @@ pub fn ehlo_ok_rsp(input: &[u8]) -> IResult<&[u8], EhloOkResp> { /// ehlo-greet = 1*(%d0-9 / %d11-12 / %d14-127) pub fn ehlo_greet(input: &[u8]) -> IResult<&[u8], &str> { fn is_valid_character(byte: u8) -> bool { - match byte { - 0..=9 | 11..=12 | 14..=127 => true, - _ => false, - } + matches!(byte, 0..=9 | 11..=12 | 14..=127) } map_res(take_while1(is_valid_character), std::str::from_utf8)(input) @@ -96,7 +93,7 @@ pub fn ehlo_line(input: &[u8]) -> IResult<&[u8], (&str, Vec<&str>)> { let (remaining, (ehlo_keyword, ehlo_params)) = parser(input)?; - Ok((remaining, (ehlo_keyword, ehlo_params.unwrap_or(vec![])))) + Ok((remaining, (ehlo_keyword, ehlo_params.unwrap_or_default()))) } /// Additional syntax of ehlo-params depends on ehlo-keyword @@ -119,10 +116,7 @@ pub fn ehlo_keyword(input: &[u8]) -> IResult<&[u8], &[u8]> { /// ehlo-param = 1*(%d33-126) pub fn ehlo_param(input: &[u8]) -> IResult<&[u8], &str> { fn is_valid_character(byte: u8) -> bool { - match byte { - 33..=126 => true, - _ => false, - } + matches!(byte, 33..=126) } map_res(take_while1(is_valid_character), std::str::from_utf8)(input)