Skip to content

Commit

Permalink
silence clippy warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Marc-Antoine Perennou <Marc-Antoine@Perennou.com>
  • Loading branch information
Keruspe committed May 19, 2023
1 parent fda1757 commit 0a85944
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 26 deletions.
6 changes: 3 additions & 3 deletions codegen/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
{
Expand All @@ -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"))
{
Expand Down Expand Up @@ -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 {
Expand Down
10 changes: 4 additions & 6 deletions codegen/src/templating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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#"
Expand Down
2 changes: 1 addition & 1 deletion tcp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ version = "=7.1.1"
path = "../uri"

[dependencies.tcp-stream]
version = "^0.25"
version = "^0.26"
default-features = false

[dependencies.tracing]
Expand Down
22 changes: 6 additions & 16 deletions uri/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -151,7 +147,7 @@ fn int_queryparam<T: FromStr<Err = ParseIntError>>(
param: &str,
) -> Result<Option<T>, String> {
url.query_pairs()
.find(|&(ref key, _)| key == param)
.find(|(key, _)| key == param)
.map_or(Ok(None), |(_, ref value)| value.parse::<T>().map(Some))
.map_err(|e: ParseIntError| e.to_string())
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -216,12 +212,6 @@ impl AMQPScheme {
}
}

impl Default for AMQPScheme {
fn default() -> Self {
AMQPScheme::AMQP
}
}

impl Default for AMQPAuthority {
fn default() -> Self {
AMQPAuthority {
Expand Down

0 comments on commit 0a85944

Please sign in to comment.