From 0a859440b4f7bfee0f1963b7b6185f8c6f48981a Mon Sep 17 00:00:00 2001 From: Marc-Antoine Perennou Date: Fri, 19 May 2023 13:51:08 +0200 Subject: [PATCH] silence clippy warnings Signed-off-by: Marc-Antoine Perennou --- codegen/src/internal.rs | 6 +++--- codegen/src/templating.rs | 10 ++++------ tcp/Cargo.toml | 2 +- uri/src/lib.rs | 22 ++++++---------------- 4 files changed, 14 insertions(+), 26 deletions(-) diff --git a/codegen/src/internal.rs b/codegen/src/internal.rs index 402062e..8d1db41 100644 --- a/codegen/src/internal.rs +++ b/codegen/src/internal.rs @@ -361,7 +361,7 @@ impl _AMQPMethod { .unwrap_or_default(); if is_reply && metadata.get("state").is_none() { if let Some(state) = class_md - .and_then(|c| c.get(&self.name.replace("-ok", ""))) + .and_then(|c| c.get(self.name.replace("-ok", ""))) .and_then(|m| m.get("metadata")) .and_then(|m| m.get("state")) { @@ -370,7 +370,7 @@ impl _AMQPMethod { } if is_reply && metadata.get("confirmation").is_none() { if let Some(confirmation) = class_md - .and_then(|c| c.get(&self.name.replace("-ok", ""))) + .and_then(|c| c.get(self.name.replace("-ok", ""))) .and_then(|m| m.get("metadata")) .and_then(|m| m.get("confirmation")) { @@ -411,7 +411,7 @@ impl _AMQPMethod { .unwrap_or(false); let amqp_type = argument.get_type(domains); if amqp_type == AMQPType::Boolean { - let mut flgs = flags.take().unwrap_or_else(Vec::new); + let mut flgs = flags.take().unwrap_or_default(); flgs.push(argument.to_flag_specs(force_default)); flags = Some(flgs); } else { diff --git a/codegen/src/templating.rs b/codegen/src/templating.rs index a1655c2..6574075 100644 --- a/codegen/src/templating.rs +++ b/codegen/src/templating.rs @@ -78,7 +78,7 @@ impl<'a> HandlebarsAMQPExtension for CodeGenerator<'a> { codegen.set_strict_mode(true); codegen - .register_template_string(template_name, template.to_string()) + .register_template_string(template_name, template) .unwrap_or_else(|e| panic!("Failed to register {} template: {}", template_name, e)); data.insert( var_name.to_string(), @@ -336,9 +336,9 @@ impl HelperDef for EachArgumentHelper { AMQPArgument::Value(_) => ("Value".to_owned(), true), AMQPArgument::Flags(_) => ("Flags".to_owned(), false), }; - block.set_local_var("index", to_json(&index)); + block.set_local_var("index", to_json(index)); block.set_local_var("last", to_json(index == len - 1)); - block.set_local_var("argument_is_value", to_json(&is_value)); + block.set_local_var("argument_is_value", to_json(is_value)); if let Some(p) = array_path { if index == 0 { let mut path = Vec::with_capacity(p.len() + 1); @@ -509,9 +509,7 @@ synchronous: {{method.synchronous}} let mut data = HashMap::new(); let mut codegen = CodeGenerator::default().register_amqp_helpers(); data.insert("protocol".to_string(), specs()); - assert!(codegen - .register_template_string("main", TEMPLATE.to_string()) - .is_ok()); + assert!(codegen.register_template_string("main", TEMPLATE).is_ok()); assert_eq!( codegen.render("main", &data).unwrap(), r#" diff --git a/tcp/Cargo.toml b/tcp/Cargo.toml index 009ea44..ab71aef 100644 --- a/tcp/Cargo.toml +++ b/tcp/Cargo.toml @@ -29,7 +29,7 @@ version = "=7.1.1" path = "../uri" [dependencies.tcp-stream] -version = "^0.25" +version = "^0.26" default-features = false [dependencies.tracing] diff --git a/uri/src/lib.rs b/uri/src/lib.rs index 12469f7..8ff419b 100644 --- a/uri/src/lib.rs +++ b/uri/src/lib.rs @@ -26,9 +26,10 @@ pub struct AMQPUri { } /// The scheme used by the AMQP connection -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, Default, PartialEq, Eq)] pub enum AMQPScheme { /// Plain AMQP + #[default] AMQP, /// Encrypted AMQP over TLS AMQPS, @@ -85,24 +86,19 @@ pub struct AMQPQueryString { } /// The SASL mechanisms supported by RabbitMQ -#[derive(Clone, Copy, Debug, PartialEq, Eq)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)] pub enum SASLMechanism { /// This is a legacy mechanism kept for backward compatibility AMQPlain, /// Delegate all authentication to the transport instead of the RabbitMQ server External, /// Default plain login, this should be supported everywhere + #[default] Plain, /// A demo of RabbitMQ SecureOk mechanism, offers the same level of security as Plain RabbitCrDemo, } -impl Default for SASLMechanism { - fn default() -> Self { - SASLMechanism::Plain - } -} - impl fmt::Display for SASLMechanism { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(match self { @@ -151,7 +147,7 @@ fn int_queryparam>( param: &str, ) -> Result, String> { url.query_pairs() - .find(|&(ref key, _)| key == param) + .find(|(key, _)| key == param) .map_or(Ok(None), |(_, ref value)| value.parse::().map(Some)) .map_err(|e: ParseIntError| e.to_string()) } @@ -184,7 +180,7 @@ impl FromStr for AMQPUri { let connection_timeout = int_queryparam(&url, "connection_timeout")?; let auth_mechanism = url .query_pairs() - .find(|&(ref key, _)| key == "auth_mechanism") + .find(|(key, _)| key == "auth_mechanism") .map_or(Ok(None), |(_, ref value)| value.parse().map(Some))?; Ok(AMQPUri { @@ -216,12 +212,6 @@ impl AMQPScheme { } } -impl Default for AMQPScheme { - fn default() -> Self { - AMQPScheme::AMQP - } -} - impl Default for AMQPAuthority { fn default() -> Self { AMQPAuthority {