From 22579cdbb4d7c24a05626136109de370c516c787 Mon Sep 17 00:00:00 2001 From: Raminder Singh Date: Wed, 4 Oct 2023 13:35:22 +0530 Subject: [PATCH] fix clippy warnings --- src/builder.rs | 20 ++++++++++---------- src/graphql.rs | 28 +++++++++++++--------------- src/gson.rs | 5 +---- src/sql_types.rs | 13 +++++-------- src/transpile.rs | 2 +- 5 files changed, 30 insertions(+), 38 deletions(-) diff --git a/src/builder.rs b/src/builder.rs index a60ab0ac..e4ba939b 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -596,7 +596,7 @@ where let args = field.args(); let allowed_args: Vec<&str> = args.iter().map(|a| a.name_.as_str()).collect(); restrict_allowed_arguments(&allowed_args, query_field)?; - let args = read_func_call_args(field, query_field, variables, &func_call_resp_type)?; + let args = read_func_call_args(field, query_field, variables, func_call_resp_type)?; let return_type_builder = match func_call_resp_type.return_type.deref() { __Type::Scalar(_) => FuncCallReturnTypeBuilder::Scalar, @@ -660,13 +660,13 @@ where for arg in field.args() { let arg_value = read_argument(&arg.name(), field, query_field, variables)?; if !arg_value.is_absent() { - let func_call_sql_arg_name = match inflected_to_sql_args.get(&arg.name()) { - Some((type_name, name)) => Some(FuncCallSqlArgName { - type_name: type_name.clone(), - name: name.clone(), - }), - None => None, - }; + let func_call_sql_arg_name = + inflected_to_sql_args + .get(&arg.name()) + .map(|(type_name, name)| FuncCallSqlArgName { + type_name: type_name.clone(), + name: name.clone(), + }); args.push((func_call_sql_arg_name, gson::gson_to_json(&arg_value)?)); }; } @@ -1234,7 +1234,7 @@ where let type_name = type_ .name() .ok_or("Encountered type without name in connection builder")?; - let field_map = field_map(&type_); + let field_map = field_map(type_); let alias = alias_or_name(query_field); match &type_ { @@ -2097,7 +2097,7 @@ impl __Schema { let mut f_builders: Vec<__FieldBuilder> = vec![]; for vec_field in vec_fields { - if vec!["__type".to_string(), "__schema".to_string()] + if ["__type".to_string(), "__schema".to_string()] .contains(&vec_field.name()) { continue; diff --git a/src/graphql.rs b/src/graphql.rs index acec1cd8..96c39d5d 100644 --- a/src/graphql.rs +++ b/src/graphql.rs @@ -108,7 +108,7 @@ impl __Schema { fn graphql_function_arg_name(&self, function: &Function, arg_name: &str) -> String { let base_type_name = - to_base_type_name(&arg_name, &None, self.inflect_names(function.schema_oid)); + to_base_type_name(arg_name, &None, self.inflect_names(function.schema_oid)); lowercase_first_letter(&base_type_name) } @@ -989,9 +989,8 @@ impl FuncCallResponseType { let inflected_name_to_sql_name: HashMap = self .function .args() - .filter_map(|(_, arg_type_name, arg_name)| match arg_name { - None => None, - Some(arg_name) => Some((arg_type_name, arg_name)), + .filter_map(|(_, arg_type_name, arg_name)| { + arg_name.map(|arg_name| (arg_type_name, arg_name)) }) .map(|(arg_type_name, arg_name)| { ( @@ -1294,7 +1293,7 @@ fn function_fields(schema: &Arc<__Schema>, volatilities: &[FunctionVolatility]) } Some(__Field { - name_: schema.graphql_function_field_name(&func), + name_: schema.graphql_function_field_name(func), type_: __Type::FuncCallResponse(FuncCallResponseType { function: Arc::clone(func), schema: Arc::clone(schema), @@ -1328,12 +1327,11 @@ fn function_args(schema: &Arc<__Schema>, func: &Arc) -> Vec<__InputVal } None => None, }) - .filter_map( - |(arg_type, arg_name)| match arg_type.to_graphql_type(None, false, schema) { - Some(t) => Some((t, arg_name)), - None => None, - }, - ) + .filter_map(|(arg_type, arg_name)| { + arg_type + .to_graphql_type(None, false, schema) + .map(|t| (t, arg_name)) + }) .map(|(arg_type, arg_name)| __InputValue { name_: schema.graphql_function_arg_name(func, arg_name), type_: arg_type, @@ -3582,7 +3580,7 @@ impl ___Type for FilterEntityType { // No filtering on composites .filter(|x| !self.schema.context.is_composite(x.type_oid)) // No filtering on json/b. they do not support = or <> - .filter(|x| !vec!["json", "jsonb"].contains(&x.type_name.as_ref())) + .filter(|x| !["json", "jsonb"].contains(&x.type_name.as_ref())) .filter_map(|col| { // Should be a scalar if let Some(utype) = sql_column_to_graphql_type(col, &self.schema) { @@ -3791,7 +3789,7 @@ impl ___Type for OrderByEntityType { // No filtering on composites .filter(|x| !self.schema.context.is_composite(x.type_oid)) // No filtering on json/b. they do not support = or <> - .filter(|x| !vec!["json", "jsonb"].contains(&x.type_name.as_ref())) + .filter(|x| !["json", "jsonb"].contains(&x.type_name.as_ref())) // TODO filter out arrays, json and composites .map(|col| __InputValue { name_: self.schema.graphql_column_field_name(col), @@ -4032,11 +4030,11 @@ impl __Schema { schema: Arc::new(self.clone()), }; if let Some(fields) = mutation.fields(true) { - if fields.len() > 0 { + if !fields.is_empty() { return true; } } - return false; + false } // queryType: __Type! diff --git a/src/gson.rs b/src/gson.rs index 2052f550..d2ed8fb3 100644 --- a/src/gson.rs +++ b/src/gson.rs @@ -19,10 +19,7 @@ pub enum Value { impl Value { pub(crate) fn is_absent(&self) -> bool { - match self { - Value::Absent => true, - _ => false, - } + matches!(self, Value::Absent) } } diff --git a/src/sql_types.rs b/src/sql_types.rs index fbe2a99b..d9aed396 100644 --- a/src/sql_types.rs +++ b/src/sql_types.rs @@ -183,7 +183,7 @@ impl<'a> Iterator for ArgsIterator<'a> { let arg_name = if let Some(arg_names) = self.arg_names { debug_assert!(arg_names.len() >= self.arg_types.len()); let arg_name = arg_names[self.index].as_str(); - if arg_name != "" { + if !arg_name.is_empty() { Some(arg_name) } else { None @@ -813,15 +813,12 @@ pub fn load_sql_context(_config: &Config) -> Result, String> { let functions = arg_type_to_func.entry(function.arg_types[0]).or_default(); functions.push(function); } - for (_, table) in &mut context.tables { + for table in &mut context.tables.values_mut() { if let Some(table) = Arc::get_mut(table) { - match arg_type_to_func.get(&table.reltype) { - Some(functions) => { - for function in functions { - table.functions.push(Arc::clone(function)); - } + if let Some(functions) = arg_type_to_func.get(&table.reltype) { + for function in functions { + table.functions.push(Arc::clone(function)); } - None => {} } } } diff --git a/src/transpile.rs b/src/transpile.rs index dc84c6dc..36eeeb54 100644 --- a/src/transpile.rs +++ b/src/transpile.rs @@ -580,7 +580,7 @@ impl FunctionCallBuilder { None, Some(from_clause), )?; - format!("{select_clause}") + select_clause.to_string() } };