Skip to content

Commit

Permalink
cargo fmt and clippy fix
Browse files Browse the repository at this point in the history
  • Loading branch information
gftea committed Oct 21, 2023
1 parent 233c978 commit 92a34fe
Show file tree
Hide file tree
Showing 17 changed files with 75 additions and 152 deletions.
1 change: 0 additions & 1 deletion amqp_serde/src/de.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@ impl<'de> Deserializer<'de> {
fn get_parsed_length(&self) -> Result<usize> {
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 {
Expand Down
17 changes: 10 additions & 7 deletions amqp_serde/src/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
}
}

Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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() {
Expand Down
4 changes: 1 addition & 3 deletions amqprs/src/api/channel/confim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
75 changes: 49 additions & 26 deletions amqprs/src/api/channel/exchange.rs
Original file line number Diff line number Diff line change
@@ -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};

Expand Down Expand Up @@ -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 {
Expand All @@ -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()),
}
}
}
Expand All @@ -81,7 +81,7 @@ impl From<ExchangeType> 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,
}
}
}
Expand All @@ -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),
}
}
}
Expand Down Expand Up @@ -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},
Expand All @@ -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]
Expand Down
4 changes: 1 addition & 3 deletions amqprs/src/api/channel/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
3 changes: 1 addition & 2 deletions amqprs/src/api/security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",

Check warning on line 69 in amqprs/src/api/security.rs

View check run for this annotation

Codecov / codecov/patch

amqprs/src/api/security.rs#L69

Added line #L69 was not covered by tests
}
}
/// Get the security challenge `response` string, to be sent to server.
Expand Down
2 changes: 1 addition & 1 deletion amqprs/src/frame/content_header.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
2 changes: 0 additions & 2 deletions amqprs/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand Down
1 change: 0 additions & 1 deletion amqprs/src/net/split_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ impl SplitConnection {
}
}


impl BufIoWriter {
// write any serializable value to socket
pub async fn write<V: Serialize>(&mut self, value: &V) -> Result<usize> {
Expand Down
8 changes: 2 additions & 6 deletions benchmarks/src/basic_consume_criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 2 additions & 6 deletions benchmarks/src/basic_pub_bencher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/src/basic_pub_criterion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
6 changes: 1 addition & 5 deletions benchmarks/src/native_consume_amqprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
8 changes: 2 additions & 6 deletions benchmarks/src/native_pub_amqprs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
4 changes: 3 additions & 1 deletion examples/src/basic_pub_sub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/src/mtls.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use amqprs::security::SecurityCredentials;
use amqprs::{
callbacks::{DefaultChannelCallback, DefaultConnectionCallback},
channel::{
Expand All @@ -9,7 +10,6 @@ use amqprs::{
};
use tokio::time;
use tracing_subscriber::{fmt, prelude::*, EnvFilter};
use amqprs::security::SecurityCredentials;

use amqprs::tls::TlsAdaptor;

Expand Down
Loading

0 comments on commit 92a34fe

Please sign in to comment.