From d1f9d6d8020843dbcd4fa6764b5abf33e56ade33 Mon Sep 17 00:00:00 2001 From: Steven Fackler Date: Thu, 15 Oct 2020 21:14:13 -0400 Subject: [PATCH] fix clippy --- codegen/src/type_gen.rs | 5 +---- postgres-protocol/src/authentication/sasl.rs | 20 ++++---------------- postgres-types/src/lib.rs | 5 +---- postgres-types/src/special.rs | 10 ++-------- 4 files changed, 8 insertions(+), 32 deletions(-) diff --git a/codegen/src/type_gen.rs b/codegen/src/type_gen.rs index 485442a3..7e92e062 100644 --- a/codegen/src/type_gen.rs +++ b/codegen/src/type_gen.rs @@ -136,10 +136,7 @@ impl<'a> DatParser<'a> { fn peek(&mut self, target: char) -> bool { self.skip_ws(); - match self.it.peek() { - Some((_, ch)) if *ch == target => true, - _ => false, - } + matches!(self.it.peek(), Some((_, ch)) if *ch == target) } fn eof(&mut self) { diff --git a/postgres-protocol/src/authentication/sasl.rs b/postgres-protocol/src/authentication/sasl.rs index c99a27a2..416b4b99 100644 --- a/postgres-protocol/src/authentication/sasl.rs +++ b/postgres-protocol/src/authentication/sasl.rs @@ -330,10 +330,7 @@ impl<'a> Parser<'a> { } fn printable(&mut self) -> io::Result<&'a str> { - self.take_while(|c| match c { - '\x21'..='\x2b' | '\x2d'..='\x7e' => true, - _ => false, - }) + self.take_while(|c| matches!(c, '\x21'..='\x2b' | '\x2d'..='\x7e')) } fn nonce(&mut self) -> io::Result<&'a str> { @@ -343,10 +340,7 @@ impl<'a> Parser<'a> { } fn base64(&mut self) -> io::Result<&'a str> { - self.take_while(|c| match c { - 'a'..='z' | 'A'..='Z' | '0'..='9' | '/' | '+' | '=' => true, - _ => false, - }) + self.take_while(|c| matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '/' | '+' | '=')) } fn salt(&mut self) -> io::Result<&'a str> { @@ -356,10 +350,7 @@ impl<'a> Parser<'a> { } fn posit_number(&mut self) -> io::Result { - let n = self.take_while(|c| match c { - '0'..='9' => true, - _ => false, - })?; + let n = self.take_while(|c| matches!(c, '0'..='9'))?; n.parse() .map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e)) } @@ -396,10 +387,7 @@ impl<'a> Parser<'a> { } fn value(&mut self) -> io::Result<&'a str> { - self.take_while(|c| match c { - '\0' | '=' | ',' => false, - _ => true, - }) + self.take_while(|c| matches!(c, '\0' | '=' | ',')) } fn server_error(&mut self) -> io::Result> { diff --git a/postgres-types/src/lib.rs b/postgres-types/src/lib.rs index 258b68ed..e9a5846e 100644 --- a/postgres-types/src/lib.rs +++ b/postgres-types/src/lib.rs @@ -144,10 +144,7 @@ const NSEC_PER_USEC: u64 = 1_000; macro_rules! accepts { ($($expected:ident),+) => ( fn accepts(ty: &$crate::Type) -> bool { - match *ty { - $($crate::Type::$expected)|+ => true, - _ => false - } + matches!(*ty, $($crate::Type::$expected)|+) } ) } diff --git a/postgres-types/src/special.rs b/postgres-types/src/special.rs index 5a2d7bc0..8579885e 100644 --- a/postgres-types/src/special.rs +++ b/postgres-types/src/special.rs @@ -75,10 +75,7 @@ impl<'a, T: FromSql<'a>> FromSql<'a> for Timestamp { } fn accepts(ty: &Type) -> bool { - match *ty { - Type::TIMESTAMP | Type::TIMESTAMPTZ if T::accepts(ty) => true, - _ => false, - } + matches!(*ty, Type::TIMESTAMP | Type::TIMESTAMPTZ if T::accepts(ty)) } } @@ -99,10 +96,7 @@ impl ToSql for Timestamp { } fn accepts(ty: &Type) -> bool { - match *ty { - Type::TIMESTAMP | Type::TIMESTAMPTZ if T::accepts(ty) => true, - _ => false, - } + matches!(*ty, Type::TIMESTAMP | Type::TIMESTAMPTZ if T::accepts(ty)) } to_sql_checked!();