From 92a34fe6bf1948cb90dd59e7c7f0ee81dbaa3b8b Mon Sep 17 00:00:00 2001 From: Simon Chen Date: Sat, 21 Oct 2023 12:51:34 +0000 Subject: [PATCH] cargo fmt and clippy fix --- amqp_serde/src/de.rs | 1 - amqp_serde/src/ser.rs | 17 ++--- amqprs/src/api/channel/confim.rs | 4 +- amqprs/src/api/channel/exchange.rs | 75 ++++++++++++++-------- amqprs/src/api/channel/tx.rs | 4 +- amqprs/src/api/security.rs | 3 +- amqprs/src/frame/content_header.rs | 2 +- amqprs/src/net/mod.rs | 2 - amqprs/src/net/split_connection.rs | 1 - benchmarks/src/basic_consume_criterion.rs | 8 +-- benchmarks/src/basic_pub_bencher.rs | 8 +-- benchmarks/src/basic_pub_criterion.rs | 6 +- benchmarks/src/native_consume_amqprs.rs | 6 +- benchmarks/src/native_pub_amqprs.rs | 8 +-- examples/src/basic_pub_sub.rs | 4 +- examples/src/mtls.rs | 2 +- rustfmt.toml | 76 ----------------------- 17 files changed, 75 insertions(+), 152 deletions(-) delete mode 100644 rustfmt.toml diff --git a/amqp_serde/src/de.rs b/amqp_serde/src/de.rs index 997208e..000ded4 100644 --- a/amqp_serde/src/de.rs +++ b/amqp_serde/src/de.rs @@ -134,7 +134,6 @@ impl<'de> Deserializer<'de> { fn get_parsed_length(&self) -> Result { match self.last_parsed_len { Some(len) if len <= u32::MAX as usize => { - let len = len; if self.input.len() < len { Err(Error::Syntax) } else { diff --git a/amqp_serde/src/ser.rs b/amqp_serde/src/ser.rs index 1476e75..a396672 100644 --- a/amqp_serde/src/ser.rs +++ b/amqp_serde/src/ser.rs @@ -236,7 +236,11 @@ where // reserve u32 for length of table self.serialize_u32(0)?; } - Ok(MapSerializer { ser: self, start, is_len_known: len.is_some() }) + Ok(MapSerializer { + ser: self, + start, + is_len_known: len.is_some(), + }) } } @@ -400,7 +404,7 @@ where mod test { use crate::to_bytes; use crate::types::*; - use serde::{Serialize, Serializer, ser::SerializeMap}; + use serde::{ser::SerializeMap, Serialize, Serializer}; use std::collections::BTreeMap; #[test] @@ -535,7 +539,6 @@ mod test { assert_eq!(expected, result); } - #[test] fn test_serialize_map_known_length_up_front() { // We use BTreeMap in order to garantee that it iterates in a sorted way @@ -552,11 +555,11 @@ mod test { { /* * In this case the Serialize impl for the map has to manage by itself - * the serialization of the map lenght + * the serialization of the map lenght */ - let len = self.0 - .iter() - .fold(0, |l, (k, v)| { l + (k.as_ref().len() + v.as_ref().len()) as u32 }); + let len = self.0.iter().fold(0, |l, (k, v)| { + l + (k.as_ref().len() + v.as_ref().len()) as u32 + }); let mut map = serializer.serialize_map(Some(self.0.len()))?; // Known up-front length map.serialize_value(&len)?; for (k, v) in self.0.iter() { diff --git a/amqprs/src/api/channel/confim.rs b/amqprs/src/api/channel/confim.rs index 7e1da43..f0db8f5 100644 --- a/amqprs/src/api/channel/confim.rs +++ b/amqprs/src/api/channel/confim.rs @@ -95,9 +95,7 @@ mod tests { let args = BasicPublishArguments::new("amq.topic", "amqprs.test.transaction"); - let basic_properties = BasicProperties::default() - .with_persistence(true) - .finish(); + let basic_properties = BasicProperties::default().with_persistence(true).finish(); let content = String::from("AMQPRS test publish confirm").into_bytes(); diff --git a/amqprs/src/api/channel/exchange.rs b/amqprs/src/api/channel/exchange.rs index 98aaff8..f0c9063 100644 --- a/amqprs/src/api/channel/exchange.rs +++ b/amqprs/src/api/channel/exchange.rs @@ -1,9 +1,9 @@ -use std::borrow::ToOwned; -use std::fmt::{Debug, Display, Formatter}; use crate::{ api::{error::Error, FieldTable}, frame::{Bind, BindOk, Declare, DeclareOk, Delete, DeleteOk, Frame, Unbind, UnbindOk}, }; +use std::borrow::ToOwned; +use std::fmt::{Debug, Display, Formatter}; use super::{Channel, Result}; @@ -33,18 +33,18 @@ pub enum ExchangeType { /// Recent history exchange RecentHistory, /// All other x-* exchange types, for example, those provided by plugins - Plugin(String) + Plugin(String), } const EXCHANGE_TYPE_FANOUT: &str = "fanout"; -const EXCHANGE_TYPE_TOPIC: &str = "topic"; -const EXCHANGE_TYPE_DIRECT: &str = "direct"; -const EXCHANGE_TYPE_HEADERS: &str = "headers"; -const EXCHANGE_TYPE_CONSISTENT_HASHING: &str = "x-consistent-hash"; -const EXCHANGE_TYPE_MODULUS_HASH: &str = "x-modulus-hash"; -const EXCHANGE_TYPE_RANDOM: &str = "x-random"; -const EXCHANGE_TYPE_JMS_TOPIC: &str = "x-jms-topic"; -const EXCHANGE_TYPE_RECENT_HISTORY: &str = "x-recent-history"; +const EXCHANGE_TYPE_TOPIC: &str = "topic"; +const EXCHANGE_TYPE_DIRECT: &str = "direct"; +const EXCHANGE_TYPE_HEADERS: &str = "headers"; +const EXCHANGE_TYPE_CONSISTENT_HASHING: &str = "x-consistent-hash"; +const EXCHANGE_TYPE_MODULUS_HASH: &str = "x-modulus-hash"; +const EXCHANGE_TYPE_RANDOM: &str = "x-random"; +const EXCHANGE_TYPE_JMS_TOPIC: &str = "x-jms-topic"; +const EXCHANGE_TYPE_RECENT_HISTORY: &str = "x-recent-history"; impl From<&str> for ExchangeType { fn from(value: &str) -> Self { @@ -58,7 +58,7 @@ impl From<&str> for ExchangeType { EXCHANGE_TYPE_RANDOM => ExchangeType::Random, EXCHANGE_TYPE_JMS_TOPIC => ExchangeType::JmsTopic, EXCHANGE_TYPE_RECENT_HISTORY => ExchangeType::RecentHistory, - other => ExchangeType::Plugin(other.to_owned()) + other => ExchangeType::Plugin(other.to_owned()), } } } @@ -81,7 +81,7 @@ impl From for String { ExchangeType::Random => EXCHANGE_TYPE_RANDOM.to_owned(), ExchangeType::JmsTopic => EXCHANGE_TYPE_JMS_TOPIC.to_owned(), ExchangeType::RecentHistory => EXCHANGE_TYPE_RECENT_HISTORY.to_owned(), - ExchangeType::Plugin(exchange_type) => exchange_type + ExchangeType::Plugin(exchange_type) => exchange_type, } } } @@ -97,8 +97,8 @@ impl Display for ExchangeType { ExchangeType::ModulusHash => Display::fmt(&EXCHANGE_TYPE_MODULUS_HASH, f), ExchangeType::Random => Display::fmt(&EXCHANGE_TYPE_RANDOM, f), ExchangeType::JmsTopic => Display::fmt(&EXCHANGE_TYPE_JMS_TOPIC, f), - ExchangeType::RecentHistory => Display::fmt(&EXCHANGE_TYPE_RECENT_HISTORY,f), - ExchangeType::Plugin(exchange_type) => Display::fmt(&exchange_type, f) + ExchangeType::RecentHistory => Display::fmt(&EXCHANGE_TYPE_RECENT_HISTORY, f), + ExchangeType::Plugin(exchange_type) => Display::fmt(&exchange_type, f), } } } @@ -535,8 +535,8 @@ impl Channel { #[cfg(test)] mod tests { use super::{ - ExchangeBindArguments, ExchangeDeclareArguments, ExchangeDeleteArguments, - ExchangeUnbindArguments, ExchangeType, + ExchangeBindArguments, ExchangeDeclareArguments, ExchangeDeleteArguments, ExchangeType, + ExchangeUnbindArguments, }; use crate::{ api::connection::{Connection, OpenConnectionArguments}, @@ -550,34 +550,57 @@ mod tests { assert_eq!(ExchangeType::Topic.to_string(), "topic"); assert_eq!(ExchangeType::Direct.to_string(), "direct"); assert_eq!(ExchangeType::Headers.to_string(), "headers"); - assert_eq!(ExchangeType::ConsistentHashing.to_string(), "x-consistent-hash"); + assert_eq!( + ExchangeType::ConsistentHashing.to_string(), + "x-consistent-hash" + ); assert_eq!(ExchangeType::Random.to_string(), "x-random"); assert_eq!(ExchangeType::JmsTopic.to_string(), "x-jms-topic"); assert_eq!(ExchangeType::RecentHistory.to_string(), "x-recent-history"); assert_eq!(ExchangeType::ModulusHash.to_string(), "x-modulus-hash"); - assert_eq!(ExchangeType::Plugin(String::from("x-custom-exchange-2")).to_string(), "x-custom-exchange-2"); + assert_eq!( + ExchangeType::Plugin(String::from("x-custom-exchange-2")).to_string(), + "x-custom-exchange-2" + ); assert_eq!(ExchangeType::from("fanout"), ExchangeType::Fanout); assert_eq!(ExchangeType::from("topic"), ExchangeType::Topic); assert_eq!(ExchangeType::from("direct"), ExchangeType::Direct); assert_eq!(ExchangeType::from("headers"), ExchangeType::Headers); - assert_eq!(ExchangeType::from("x-consistent-hash"), ExchangeType::ConsistentHashing); + assert_eq!( + ExchangeType::from("x-consistent-hash"), + ExchangeType::ConsistentHashing + ); assert_eq!(ExchangeType::from("x-random"), ExchangeType::Random); assert_eq!(ExchangeType::from("x-jms-topic"), ExchangeType::JmsTopic); - assert_eq!(ExchangeType::from("x-modulus-hash"), ExchangeType::ModulusHash); - assert_eq!(ExchangeType::from("x-custom-exchange-2"), ExchangeType::Plugin(String::from("x-custom-exchange-2"))); + assert_eq!( + ExchangeType::from("x-modulus-hash"), + ExchangeType::ModulusHash + ); + assert_eq!( + ExchangeType::from("x-custom-exchange-2"), + ExchangeType::Plugin(String::from("x-custom-exchange-2")) + ); assert_eq!(String::from(ExchangeType::Fanout), "fanout"); assert_eq!(String::from(ExchangeType::Topic), "topic"); assert_eq!(String::from(ExchangeType::Direct), "direct"); assert_eq!(String::from(ExchangeType::Headers), "headers"); assert_eq!(String::from(ExchangeType::ModulusHash), "x-modulus-hash"); - assert_eq!(String::from(ExchangeType::ConsistentHashing), "x-consistent-hash"); - assert_eq!(String::from(ExchangeType::RecentHistory), "x-recent-history"); + assert_eq!( + String::from(ExchangeType::ConsistentHashing), + "x-consistent-hash" + ); + assert_eq!( + String::from(ExchangeType::RecentHistory), + "x-recent-history" + ); assert_eq!(String::from(ExchangeType::Random), "x-random"); assert_eq!(String::from(ExchangeType::JmsTopic), "x-jms-topic"); - assert_eq!(String::from(ExchangeType::Plugin(String::from("x-custom-exchange-3"))), "x-custom-exchange-3"); - + assert_eq!( + String::from(ExchangeType::Plugin(String::from("x-custom-exchange-3"))), + "x-custom-exchange-3" + ); } #[tokio::test] diff --git a/amqprs/src/api/channel/tx.rs b/amqprs/src/api/channel/tx.rs index 2601187..894d60a 100644 --- a/amqprs/src/api/channel/tx.rs +++ b/amqprs/src/api/channel/tx.rs @@ -120,9 +120,7 @@ mod tests { let args = BasicPublishArguments::new("amq.topic", "amqprs.test.transaction"); - let basic_properties = BasicProperties::default() - .with_persistence(true) - .finish(); + let basic_properties = BasicProperties::default().with_persistence(true).finish(); let content = String::from("AMQPRS test transactions").into_bytes(); diff --git a/amqprs/src/api/security.rs b/amqprs/src/api/security.rs index 9be2eaf..b5c4e3d 100644 --- a/amqprs/src/api/security.rs +++ b/amqprs/src/api/security.rs @@ -61,13 +61,12 @@ impl SecurityCredentials { } } - /// Get the name of authentication mechanism of current credential pub(crate) fn get_mechanism_name(&self) -> &str { match self.mechanism { AuthenticationMechanism::PLAIN => "PLAIN", AuthenticationMechanism::AMQPLAIN => "AMQPLAIN", - AuthenticationMechanism::EXTERNAL => "EXTERNAL" + AuthenticationMechanism::EXTERNAL => "EXTERNAL", } } /// Get the security challenge `response` string, to be sent to server. diff --git a/amqprs/src/frame/content_header.rs b/amqprs/src/frame/content_header.rs index 35a15e5..3de2b0e 100644 --- a/amqprs/src/frame/content_header.rs +++ b/amqprs/src/frame/content_header.rs @@ -1,8 +1,8 @@ use std::fmt; +use crate::{DELIVERY_MODE_PERSISTENT, DELIVERY_MODE_TRANSIENT}; use amqp_serde::types::{FieldTable, LongLongUint, Octect, ShortStr, ShortUint, TimeStamp}; use serde::{de::Visitor, Deserialize, Serialize}; -use crate::{DELIVERY_MODE_PERSISTENT, DELIVERY_MODE_TRANSIENT}; use super::Frame; diff --git a/amqprs/src/net/mod.rs b/amqprs/src/net/mod.rs index 06518f4..d395855 100644 --- a/amqprs/src/net/mod.rs +++ b/amqprs/src/net/mod.rs @@ -5,8 +5,6 @@ mod reader_handler; mod split_connection; mod writer_handler; - - pub(crate) use channel_manager::*; pub(crate) use error::*; pub(crate) use reader_handler::*; diff --git a/amqprs/src/net/split_connection.rs b/amqprs/src/net/split_connection.rs index 2684237..97c3c5e 100644 --- a/amqprs/src/net/split_connection.rs +++ b/amqprs/src/net/split_connection.rs @@ -187,7 +187,6 @@ impl SplitConnection { } } - impl BufIoWriter { // write any serializable value to socket pub async fn write(&mut self, value: &V) -> Result { diff --git a/benchmarks/src/basic_consume_criterion.rs b/benchmarks/src/basic_consume_criterion.rs index 32d3a39..05932a8 100644 --- a/benchmarks/src/basic_consume_criterion.rs +++ b/benchmarks/src/basic_consume_criterion.rs @@ -110,13 +110,9 @@ mod client_amqprs { // publish messages of variable sizes - for &i in msg_size_list.iter().take(count) { + for &i in msg_size_list.iter().take(count) { channel - .basic_publish( - BasicProperties::default(), - vec![0xc5; i], - pubargs.clone(), - ) + .basic_publish(BasicProperties::default(), vec![0xc5; i], pubargs.clone()) .await .unwrap(); } diff --git a/benchmarks/src/basic_pub_bencher.rs b/benchmarks/src/basic_pub_bencher.rs index 2cd0f7c..57be4f6 100644 --- a/benchmarks/src/basic_pub_bencher.rs +++ b/benchmarks/src/basic_pub_bencher.rs @@ -95,11 +95,7 @@ mod client_amqprs { // publish messages of variable sizes for &i in msg_size_list.iter().take(count) { channel - .basic_publish( - BasicProperties::default(), - vec![0xc5; i], - pubargs.clone(), - ) + .basic_publish(BasicProperties::default(), vec![0xc5; i], pubargs.clone()) .await .unwrap(); } @@ -203,7 +199,7 @@ mod client_lapin { assert_eq!(0, q_state.message_count()); // publish messages of variable sizes - for &i in msg_size_list.iter().take(count) { + for &i in msg_size_list.iter().take(count) { let _confirm = channel .basic_publish( exchange_name, diff --git a/benchmarks/src/basic_pub_criterion.rs b/benchmarks/src/basic_pub_criterion.rs index 339df75..4e29599 100644 --- a/benchmarks/src/basic_pub_criterion.rs +++ b/benchmarks/src/basic_pub_criterion.rs @@ -96,11 +96,7 @@ mod client_amqprs { // publish messages of variable sizes for &i in msg_size_list.iter().take(count) { channel - .basic_publish( - BasicProperties::default(), - vec![0xc5; i], - pubargs.clone(), - ) + .basic_publish(BasicProperties::default(), vec![0xc5; i], pubargs.clone()) .await .unwrap(); } diff --git a/benchmarks/src/native_consume_amqprs.rs b/benchmarks/src/native_consume_amqprs.rs index 12ab5ec..93b4636 100644 --- a/benchmarks/src/native_consume_amqprs.rs +++ b/benchmarks/src/native_consume_amqprs.rs @@ -83,11 +83,7 @@ fn main() { // publish messages of variable sizes for &i in msg_size_list.iter().take(count) { channel - .basic_publish( - BasicProperties::default(), - vec![0xc5; i], - pubargs.clone(), - ) + .basic_publish(BasicProperties::default(), vec![0xc5; i], pubargs.clone()) .await .unwrap(); } diff --git a/benchmarks/src/native_pub_amqprs.rs b/benchmarks/src/native_pub_amqprs.rs index f797776..a1f19fe 100644 --- a/benchmarks/src/native_pub_amqprs.rs +++ b/benchmarks/src/native_pub_amqprs.rs @@ -78,13 +78,9 @@ fn main() { ////////////////////////////////////////////////////////////////////////////// let now = std::time::Instant::now(); // publish messages of variable sizes - for &i in msg_size_list.iter().take(count) { + for &i in msg_size_list.iter().take(count) { channel - .basic_publish( - BasicProperties::default(), - vec![0xc5; i], - pubargs.clone(), - ) + .basic_publish(BasicProperties::default(), vec![0xc5; i], pubargs.clone()) .await .unwrap(); } diff --git a/examples/src/basic_pub_sub.rs b/examples/src/basic_pub_sub.rs index a68991f..84c0d4b 100644 --- a/examples/src/basic_pub_sub.rs +++ b/examples/src/basic_pub_sub.rs @@ -44,7 +44,9 @@ async fn main() { // declare a durable queue let (queue_name, _, _) = channel - .queue_declare(QueueDeclareArguments::durable_client_named("amqprs.examples.basic")) + .queue_declare(QueueDeclareArguments::durable_client_named( + "amqprs.examples.basic", + )) .await .unwrap() .unwrap(); diff --git a/examples/src/mtls.rs b/examples/src/mtls.rs index 090940e..d5eadc3 100644 --- a/examples/src/mtls.rs +++ b/examples/src/mtls.rs @@ -1,3 +1,4 @@ +use amqprs::security::SecurityCredentials; use amqprs::{ callbacks::{DefaultChannelCallback, DefaultConnectionCallback}, channel::{ @@ -9,7 +10,6 @@ use amqprs::{ }; use tokio::time; use tracing_subscriber::{fmt, prelude::*, EnvFilter}; -use amqprs::security::SecurityCredentials; use amqprs::tls::TlsAdaptor; diff --git a/rustfmt.toml b/rustfmt.toml deleted file mode 100644 index 4e47f45..0000000 --- a/rustfmt.toml +++ /dev/null @@ -1,76 +0,0 @@ -max_width = 100 -hard_tabs = false -tab_spaces = 4 -newline_style = "Auto" -indent_style = "Block" -use_small_heuristics = "Default" -fn_call_width = 60 -attr_fn_like_width = 70 -struct_lit_width = 18 -struct_variant_width = 35 -array_width = 60 -chain_width = 60 -single_line_if_else_max_width = 50 -wrap_comments = false -format_code_in_doc_comments = false -doc_comment_code_block_width = 100 -comment_width = 80 -normalize_comments = false -normalize_doc_attributes = false -format_strings = false -format_macro_matchers = false -format_macro_bodies = true -hex_literal_case = "Preserve" -empty_item_single_line = true -struct_lit_single_line = true -fn_single_line = false -where_single_line = false -imports_indent = "Block" -imports_layout = "Mixed" -imports_granularity = "Preserve" -group_imports = "Preserve" -reorder_imports = true -reorder_modules = true -reorder_impl_items = false -type_punctuation_density = "Wide" -space_before_colon = false -space_after_colon = true -spaces_around_ranges = false -binop_separator = "Front" -remove_nested_parens = true -combine_control_expr = true -short_array_element_width_threshold = 10 -overflow_delimited_expr = false -struct_field_align_threshold = 0 -enum_discrim_align_threshold = 0 -match_arm_blocks = true -match_arm_leading_pipes = "Never" -force_multiline_blocks = false -fn_args_layout = "Tall" -brace_style = "SameLineWhere" -control_brace_style = "AlwaysSameLine" -trailing_semicolon = true -trailing_comma = "Vertical" -match_block_trailing_comma = false -blank_lines_upper_bound = 1 -blank_lines_lower_bound = 0 -edition = "2021" -version = "One" -inline_attribute_width = 0 -format_generated_files = true -merge_derives = true -use_try_shorthand = false -use_field_init_shorthand = false -force_explicit_abi = true -condense_wildcard_suffixes = false -color = "Auto" -required_version = "1.5.1" -unstable_features = false -disable_all_formatting = false -skip_children = false -hide_parse_errors = false -error_on_line_overflow = false -error_on_unformatted = false -ignore = [] -emit_mode = "Files" -make_backup = false