Skip to content

Commit

Permalink
fix: clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mythrnr committed Oct 19, 2023
1 parent c20f309 commit c8eb703
Show file tree
Hide file tree
Showing 15 changed files with 98 additions and 110 deletions.
22 changes: 11 additions & 11 deletions raiden/src/condition/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,21 +79,21 @@ impl<T: Clone> ConditionBuilder<T> for ConditionFilledOrWaitOperator<T> {
impl<T: Clone> ConditionBuilder<T> for ConditionFilled<T> {
fn build(self) -> (String, super::AttributeNames, super::AttributeValues) {
let (right_str, right_names, right_values) = match self.operator {
super::condition::Operator::And(s, m, v) => (format!("AND ({})", s), m, v),
super::condition::Operator::Or(s, m, v) => (format!("OR ({})", s), m, v),
super::condition::Operator::And(s, m, v) => (format!("AND ({s})"), m, v),
super::condition::Operator::Or(s, m, v) => (format!("OR ({s})"), m, v),
};
let left_str = self.cond.to_string();
let left_names = self.cond.to_attr_names();
let left_values = self.cond.into_attr_values();
if self.not {
(
format!("NOT ({}) {}", left_str, right_str),
format!("NOT ({left_str}) {right_str}"),
super::merge_map(left_names, right_names),
super::merge_map(left_values, right_values),
)
} else {
(
format!("{} {}", left_str, right_str),
format!("{left_str} {right_str}"),
super::merge_map(left_names, right_names),
super::merge_map(left_values, right_values),
)
Expand All @@ -106,10 +106,10 @@ impl std::string::ToString for ConditionFunctionExpression {
use crypto::digest::Digest;
use crypto::md5::Md5;
match self {
Self::AttributeExists(path) => format!("attribute_exists(#{})", path),
Self::AttributeNotExists(path) => format!("attribute_not_exists(#{})", path),
Self::AttributeExists(path) => format!("attribute_exists(#{path})"),
Self::AttributeNotExists(path) => format!("attribute_not_exists(#{path})"),
Self::AttributeType(path, attribute_type) => {
format!("attribute_type(#{}, :type{})", path, attribute_type)
format!("attribute_type(#{path}, :type{attribute_type})")
}
Self::BeginsWith(path, s) => {
let mut md5 = Md5::new();
Expand Down Expand Up @@ -137,7 +137,7 @@ impl super::ToAttrNames for ConditionFunctionExpression {
| Self::AttributeType(path, _)
| Self::AttributeExists(path)
| Self::AttributeNotExists(path) => {
m.insert(format!("#{}", path), path.clone());
m.insert(format!("#{path}"), path.clone());
}
_ => {}
}
Expand All @@ -153,7 +153,7 @@ impl super::IntoAttrValues for ConditionFunctionExpression {
match self {
Self::AttributeType(_path, t) => {
m.insert(
format!(":type{}", t),
format!(":type{t}"),
super::AttributeValue {
s: Some(t.to_string()),
..super::AttributeValue::default()
Expand Down Expand Up @@ -240,8 +240,8 @@ pub enum AttrOrPlaceholder {
impl std::string::ToString for AttrOrPlaceholder {
fn to_string(&self) -> String {
match self {
Self::Placeholder(p) => format!(":{}", p),
Self::Attr(a) => format!("#{}", a),
Self::Placeholder(p) => format!(":{p}"),
Self::Attr(a) => format!("#{a}"),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion raiden/src/errors/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl fmt::Display for RaidenTransactionCancellationReasons {
})
.collect::<Vec<_>>()
.join(", ");
f.write_fmt(format_args!("[{}]", reasons))
f.write_fmt(format_args!("[{reasons}]"))
}
}

Expand Down
76 changes: 35 additions & 41 deletions raiden/src/filter_expression/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,57 +105,57 @@ impl<T> FilterExpressionBuilder<T> for FilterExpressionFilledOrWaitOperator<T> {
let mut attr_names: super::AttributeNames = std::collections::HashMap::new();
let mut attr_values: super::AttributeValues = std::collections::HashMap::new();

attr_names.insert(format!("#{}", attr_name), attr_name.clone());
attr_names.insert(format!("#{attr_name}"), attr_name.clone());
let left_cond = if self.is_size {
format!("size(#{})", attr_name)
format!("size(#{attr_name})")
} else {
format!("#{}", attr_name)
format!("#{attr_name}")
};
match self.cond {
FilterExpressionTypes::Eq(placeholder, value) => {
attr_values.insert(placeholder.to_string(), value);
(
format!("{} = {}", left_cond, placeholder),
format!("{left_cond} = {placeholder}"),
attr_names,
attr_values,
)
}
FilterExpressionTypes::Not(placeholder, value) => {
attr_values.insert(placeholder.to_string(), value);
(
format!("{} <> {}", left_cond, placeholder),
format!("{left_cond} <> {placeholder}"),
attr_names,
attr_values,
)
}
FilterExpressionTypes::Gt(placeholder, value) => {
attr_values.insert(placeholder.to_string(), value);
(
format!("{} > {}", left_cond, placeholder),
format!("{left_cond} > {placeholder}"),
attr_names,
attr_values,
)
}
FilterExpressionTypes::Ge(placeholder, value) => {
attr_values.insert(placeholder.to_string(), value);
(
format!("{} >= {}", left_cond, placeholder),
format!("{left_cond} >= {placeholder}"),
attr_names,
attr_values,
)
}
FilterExpressionTypes::Le(placeholder, value) => {
attr_values.insert(placeholder.to_string(), value);
(
format!("{} <= {}", left_cond, placeholder),
format!("{left_cond} <= {placeholder}"),
attr_names,
attr_values,
)
}
FilterExpressionTypes::Lt(placeholder, value) => {
attr_values.insert(placeholder.to_string(), value);
(
format!("{} < {}", left_cond, placeholder),
format!("{left_cond} < {placeholder}"),
attr_names,
attr_values,
)
Expand All @@ -164,10 +164,7 @@ impl<T> FilterExpressionBuilder<T> for FilterExpressionFilledOrWaitOperator<T> {
attr_values.insert(placeholder1.to_string(), value1);
attr_values.insert(placeholder2.to_string(), value2);
(
format!(
"{} BETWEEN {} AND {}",
left_cond, placeholder1, placeholder2
),
format!("{left_cond} BETWEEN {placeholder1} AND {placeholder2}"),
attr_names,
attr_values,
)
Expand All @@ -182,41 +179,41 @@ impl<T> FilterExpressionBuilder<T> for FilterExpressionFilledOrWaitOperator<T> {
attr_values.insert(placeholder, value);
}
(
format!("{} IN ({})", left_cond, placeholders),
format!("{left_cond} IN ({placeholders})"),
attr_names,
attr_values,
)
}
FilterExpressionTypes::BeginsWith(placeholder, value) => {
attr_values.insert(placeholder.to_string(), value);
(
format!("begins_with(#{}, {})", attr_name, placeholder),
format!("begins_with(#{attr_name}, {placeholder})"),
attr_names,
attr_values,
)
}
FilterExpressionTypes::AttributeExists() => (
format!("attribute_exists(#{})", attr_name),
format!("attribute_exists(#{attr_name})"),
attr_names,
attr_values,
),
FilterExpressionTypes::AttributeNotExists() => (
format!("attribute_not_exists(#{})", attr_name),
format!("attribute_not_exists(#{attr_name})"),
attr_names,
attr_values,
),
FilterExpressionTypes::AttributeType(placeholder, attribute_type) => {
attr_values.insert(placeholder.to_string(), attribute_type.into_attr());
(
format!("attribute_type(#{}, {})", attr_name, placeholder),
format!("attribute_type(#{attr_name}, {placeholder})"),
attr_names,
attr_values,
)
}
FilterExpressionTypes::Contains(placeholder, value) => {
attr_values.insert(placeholder.to_string(), value);
(
format!("contains(#{}, {})", attr_name, placeholder),
format!("contains(#{attr_name}, {placeholder})"),
attr_names,
attr_values,
)
Expand All @@ -228,52 +225,49 @@ impl<T> FilterExpressionBuilder<T> for FilterExpressionFilledOrWaitOperator<T> {
impl<T> FilterExpressionBuilder<T> for FilterExpressionFilled<T> {
fn build(self) -> (String, super::AttributeNames, super::AttributeValues) {
let (right_str, right_names, right_values) = match self.operator {
FilterExpressionOperator::And(s, m, v) => (format!("AND ({})", s), m, v),
FilterExpressionOperator::Or(s, m, v) => (format!("OR ({})", s), m, v),
FilterExpressionOperator::And(s, m, v) => (format!("AND ({s})"), m, v),
FilterExpressionOperator::Or(s, m, v) => (format!("OR ({s})"), m, v),
};

let attr_name = self.attr;
let mut left_names: super::AttributeNames = std::collections::HashMap::new();
let mut left_values: super::AttributeValues = std::collections::HashMap::new();
left_names.insert(format!("#{}", attr_name), attr_name.clone());
left_names.insert(format!("#{attr_name}"), attr_name.clone());
let left_cond = if self.is_size {
format!("size(#{})", attr_name)
format!("size(#{attr_name})")
} else {
format!("#{}", attr_name)
format!("#{attr_name}")
};

let left_str = match self.cond {
FilterExpressionTypes::Eq(placeholder, value) => {
left_values.insert(placeholder.clone(), value);
format!("{} = {}", left_cond, placeholder)
format!("{left_cond} = {placeholder}")
}
FilterExpressionTypes::Not(placeholder, value) => {
left_values.insert(placeholder.clone(), value);
format!("{} <> {}", left_cond, placeholder)
format!("{left_cond} <> {placeholder}")
}
FilterExpressionTypes::Gt(placeholder, value) => {
left_values.insert(placeholder.clone(), value);
format!("{} > {}", left_cond, placeholder)
format!("{left_cond} > {placeholder}")
}
FilterExpressionTypes::Ge(placeholder, value) => {
left_values.insert(placeholder.clone(), value);
format!("{} >= {}", left_cond, placeholder)
format!("{left_cond} >= {placeholder}")
}
FilterExpressionTypes::Le(placeholder, value) => {
left_values.insert(placeholder.clone(), value);
format!("{} <= {}", left_cond, placeholder)
format!("{left_cond} <= {placeholder}")
}
FilterExpressionTypes::Lt(placeholder, value) => {
left_values.insert(placeholder.clone(), value);
format!("{} < {}", left_cond, placeholder)
format!("{left_cond} < {placeholder}")
}
FilterExpressionTypes::Between(placeholder1, value1, placeholder2, value2) => {
left_values.insert(placeholder1.clone(), value1);
left_values.insert(placeholder2.clone(), value2);
format!(
"{} BETWEEN {} AND {}",
left_cond, placeholder1, placeholder2
)
format!("{left_cond} BETWEEN {placeholder1} AND {placeholder2}")
}
FilterExpressionTypes::In(attributes) => {
let placeholders = attributes
Expand All @@ -284,29 +278,29 @@ impl<T> FilterExpressionBuilder<T> for FilterExpressionFilled<T> {
for (placeholder, value) in attributes {
left_values.insert(placeholder, value);
}
format!("{} IN ({})", attr_name, placeholders)
format!("{attr_name} IN ({placeholders})")
}
FilterExpressionTypes::BeginsWith(placeholder, value) => {
left_values.insert(placeholder.clone(), value);
format!("begins_with(#{}, {})", attr_name, placeholder)
format!("begins_with(#{attr_name}, {placeholder})")
}
FilterExpressionTypes::AttributeExists() => {
format!("attribute_exists(#{})", attr_name)
format!("attribute_exists(#{attr_name})")
}
FilterExpressionTypes::AttributeNotExists() => {
format!("attribute_not_exists(#{})", attr_name)
format!("attribute_not_exists(#{attr_name})")
}
FilterExpressionTypes::AttributeType(placeholder, attribute_type) => {
left_values.insert(placeholder.clone(), attribute_type.into_attr());
format!("attribute_type(#{}, {})", attr_name, placeholder)
format!("attribute_type(#{attr_name}, {placeholder})")
}
FilterExpressionTypes::Contains(placeholder, value) => {
left_values.insert(placeholder.clone(), value);
format!("contains(#{}, {})", attr_name, placeholder)
format!("contains(#{attr_name}, {placeholder})")
}
};
(
format!("{} {}", left_str, right_str),
format!("{left_str} {right_str}"),
super::merge_map(left_names, right_names),
super::merge_map(left_values, right_values),
)
Expand Down
Loading

0 comments on commit c8eb703

Please sign in to comment.