]> git.proxmox.com Git - proxmox.git/commitdiff
clippy: remove unnecessary reference taking
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 2 Dec 2021 07:58:10 +0000 (08:58 +0100)
committerFabian Grünbichler <f.gruenbichler@proxmox.com>
Thu, 2 Dec 2021 07:58:10 +0000 (08:58 +0100)
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
12 files changed:
proxmox-async/src/compression.rs
proxmox-router/src/cli/command.rs
proxmox-router/src/cli/completion.rs
proxmox-router/src/cli/format.rs
proxmox-router/src/cli/getopts.rs
proxmox-router/src/cli/text_table.rs
proxmox-router/src/format.rs
proxmox-router/src/permission.rs
proxmox-router/src/rpc_environment.rs
proxmox-schema/src/format.rs
proxmox-schema/src/schema.rs
proxmox-section-config/src/lib.rs

index e36f0d5e276122459af56c64b51848cdb777b3a7..68b73d59c64966a50ab3c52cfd3e81ef0a166018 100644 (file)
@@ -80,7 +80,7 @@ impl<T> DeflateEncoder<T> {
         let old_out = self.compressor.total_out();
         let res = self
             .compressor
-            .compress(&inbuf[..], self.buffer.get_free_mut_slice(), flush)?;
+            .compress(inbuf, self.buffer.get_free_mut_slice(), flush)?;
         let new_in = (self.compressor.total_in() - old_in) as usize;
         let new_out = (self.compressor.total_out() - old_out) as usize;
         self.buffer.add_size(new_out);
index c66797a83a549f70e08865f3a54475b9c19cc151..1b05078c806bd06ea6057ed8c84b9301a9534ed4 100644 (file)
@@ -61,7 +61,7 @@ async fn handle_simple_command_future(
     let params = parse_arguments(prefix, cli_cmd, args)?;
 
     match cli_cmd.info.handler {
-        ApiHandler::Sync(handler) => match (handler)(params, &cli_cmd.info, &mut rpcenv) {
+        ApiHandler::Sync(handler) => match (handler)(params, cli_cmd.info, &mut rpcenv) {
             Ok(value) => {
                 if value != Value::Null {
                     println!("Result: {}", serde_json::to_string_pretty(&value).unwrap());
@@ -73,7 +73,7 @@ async fn handle_simple_command_future(
             }
         },
         ApiHandler::Async(handler) => {
-            let future = (handler)(params, &cli_cmd.info, &mut rpcenv);
+            let future = (handler)(params, cli_cmd.info, &mut rpcenv);
 
             match future.await {
                 Ok(value) => {
@@ -107,7 +107,7 @@ fn handle_simple_command(
     let params = parse_arguments(prefix, cli_cmd, args)?;
 
     match cli_cmd.info.handler {
-        ApiHandler::Sync(handler) => match (handler)(params, &cli_cmd.info, &mut rpcenv) {
+        ApiHandler::Sync(handler) => match (handler)(params, cli_cmd.info, &mut rpcenv) {
             Ok(value) => {
                 if value != Value::Null {
                     println!("Result: {}", serde_json::to_string_pretty(&value).unwrap());
@@ -119,7 +119,7 @@ fn handle_simple_command(
             }
         },
         ApiHandler::Async(handler) => {
-            let future = (handler)(params, &cli_cmd.info, &mut rpcenv);
+            let future = (handler)(params, cli_cmd.info, &mut rpcenv);
             if let Some(run) = run {
                 match (run)(future) {
                     Ok(value) => {
@@ -172,7 +172,7 @@ fn parse_nested_command<'a>(
             });
 
             let err_msg = format!("no command specified.\nPossible commands: {}", list);
-            print_nested_usage_error(&prefix, map, &err_msg);
+            print_nested_usage_error(prefix, map, &err_msg);
             return Err(format_err!("{}", err_msg));
         }
 
@@ -182,7 +182,7 @@ fn parse_nested_command<'a>(
             Some(cmd) => cmd,
             None => {
                 let err_msg = format!("no such command '{}'", command);
-                print_nested_usage_error(&prefix, map, &err_msg);
+                print_nested_usage_error(prefix, map, &err_msg);
                 return Err(format_err!("{}", err_msg));
             }
         };
@@ -192,7 +192,7 @@ fn parse_nested_command<'a>(
         match sub_cmd {
             CommandLineInterface::Simple(cli_cmd) => {
                 //return handle_simple_command(&prefix, cli_cmd, args).await;
-                return Ok(&cli_cmd);
+                return Ok(cli_cmd);
             }
             CommandLineInterface::Nested(new_map) => map = new_map,
         }
@@ -297,12 +297,12 @@ pub async fn handle_command_future(
 
     let result = match &*def {
         CommandLineInterface::Simple(ref cli_cmd) => {
-            handle_simple_command_future(&prefix, &cli_cmd, args, rpcenv).await
+            handle_simple_command_future(prefix, cli_cmd, args, rpcenv).await
         }
         CommandLineInterface::Nested(ref map) => {
             let mut prefix = prefix.to_string();
-            let cli_cmd = parse_nested_command(&mut prefix, &map, &mut args)?;
-            handle_simple_command_future(&prefix, &cli_cmd, args, rpcenv).await
+            let cli_cmd = parse_nested_command(&mut prefix, map, &mut args)?;
+            handle_simple_command_future(&prefix, cli_cmd, args, rpcenv).await
         }
     };
 
@@ -326,12 +326,12 @@ pub fn handle_command(
 
     let result = match &*def {
         CommandLineInterface::Simple(ref cli_cmd) => {
-            handle_simple_command(&prefix, &cli_cmd, args, rpcenv, run)
+            handle_simple_command(prefix, cli_cmd, args, rpcenv, run)
         }
         CommandLineInterface::Nested(ref map) => {
             let mut prefix = prefix.to_string();
-            let cli_cmd = parse_nested_command(&mut prefix, &map, &mut args)?;
-            handle_simple_command(&prefix, &cli_cmd, args, rpcenv, run)
+            let cli_cmd = parse_nested_command(&mut prefix, map, &mut args)?;
+            handle_simple_command(&prefix, cli_cmd, args, rpcenv, run)
         }
     };
 
@@ -357,10 +357,10 @@ fn prepare_cli_command(def: &CommandLineInterface) -> (String, Vec<String>) {
         if args[0] == "printdoc" {
             let usage = match def {
                 CommandLineInterface::Simple(cli_cmd) => {
-                    generate_usage_str(&prefix, &cli_cmd, DocumentationFormat::ReST, "", &[])
+                    generate_usage_str(&prefix, cli_cmd, DocumentationFormat::ReST, "", &[])
                 }
                 CommandLineInterface::Nested(map) => {
-                    generate_nested_usage(&prefix, &map, DocumentationFormat::ReST)
+                    generate_nested_usage(&prefix, map, DocumentationFormat::ReST)
                 }
             };
             println!("{}", usage);
index 42b19e5feb51c306d2e8c529780f6fa4b8cf7b2b..303ab40662313b5ac1c414da47d2a2dbeda16af9 100644 (file)
@@ -67,7 +67,7 @@ fn get_property_completion(
         }
         Schema::Array(ArraySchema { items, .. }) => {
             if let Schema::String(_) = items {
-                return get_property_completion(&items, name, completion_functions, arg, param);
+                return get_property_completion(items, name, completion_functions, arg, param);
             }
         }
         _ => {}
@@ -101,7 +101,7 @@ fn get_simple_completion(
                 record_done_argument(done, cli_cmd.info.parameters, prop_name, &args[0]);
                 if args.len() > 1 {
                     if is_array_param {
-                        return get_simple_completion(cli_cmd, done, &arg_param[..], &args[1..]);
+                        return get_simple_completion(cli_cmd, done, arg_param, &args[1..]);
                     } else {
                         return get_simple_completion(cli_cmd, done, &arg_param[1..], &args[1..]);
                     }
@@ -153,7 +153,7 @@ fn get_simple_completion(
                     schema,
                     prop_name,
                     &cli_cmd.completion_functions,
-                    &prefix,
+                    prefix,
                     done,
                 );
             }
@@ -223,9 +223,9 @@ impl CommandLineInterface {
             CommandLineInterface::Simple(cli_cmd) => {
                 let mut done: HashMap<String, String> = HashMap::new();
                 cli_cmd.fixed_param.iter().for_each(|(key, value)| {
-                    record_done_argument(&mut done, cli_cmd.info.parameters, &key, &value);
+                    record_done_argument(&mut done, cli_cmd.info.parameters, key, value);
                 });
-                get_simple_completion(cli_cmd, &mut done, &cli_cmd.arg_param, args)
+                get_simple_completion(cli_cmd, &mut done, cli_cmd.arg_param, args)
             }
             CommandLineInterface::Nested(map) => {
                 if args.is_empty() {
index c36f44bdc2a2217ab337bcaa221e5286db66793c..a84c0bc0fb7a466eb94945704391389545c8ad6b 100644 (file)
@@ -47,7 +47,7 @@ pub fn format_and_print_result_full(
     } else if output_format == "json" {
         println!("{}", serde_json::to_string(&result).unwrap());
     } else if output_format == "text" {
-        if let Err(err) = value_to_text(std::io::stdout(), result, &return_type.schema, options) {
+        if let Err(err) = value_to_text(std::io::stdout(), result, return_type.schema, options) {
             eprintln!("unable to format result: {}", err);
         }
     } else {
index e41766a8eda2df0711f80e50983ffe76203091ab..8608f3a7f0feadc9fc4859eca195a65f71a6f88b 100644 (file)
@@ -152,7 +152,7 @@ pub fn parse_arguments<T: AsRef<str>>(
 
     for i in 0..arg_param.len() {
         let name = arg_param[i];
-        if let Some((optional, param_schema)) = schema.lookup(&name) {
+        if let Some((optional, param_schema)) = schema.lookup(name) {
             if i == arg_param.len() - 1 {
                 last_arg_param_is_optional = optional;
                 if let Schema::Array(_) = param_schema {
@@ -250,7 +250,7 @@ fn test_argument_paramenter() {
     let args = vec!["-enable", "local"];
     let res = parse_arguments(
         &args,
-        &vec!["storage"],
+        &["storage"],
         &HashMap::new(),
         ParameterSchema::from(&PARAMETERS),
     );
index 1932034100197e62d80e8abfebc949ea45fe72d5..fd5f079e2622727e9aa6b2d60318840e37c1d0e9 100644 (file)
@@ -476,7 +476,7 @@ fn format_table<W: Write>(
         let mut cells = Vec::new();
         for entry in list.iter() {
             let result = if let Some(renderer) = renderer {
-                (renderer)(&entry[name], &entry)
+                (renderer)(&entry[name], entry)
             } else {
                 data_to_text(&entry[name], prop_schema)
             };
@@ -691,7 +691,7 @@ fn format_object<W: Write>(
         });
 
         let result = if let Some(renderer) = renderer {
-            (renderer)(&data[name], &data)
+            (renderer)(&data[name], data)
         } else {
             data_to_text(&data[name], prop_schema)
         };
index 32c1009fbb05763bb20a99f7ed44590194421a89..9f805b3ce7c03429cd84b641cbdec947640a4476 100644 (file)
@@ -14,7 +14,7 @@ fn dump_method_definition(method: &str, path: &str, def: Option<&ApiMethod>) ->
     match def {
         None => None,
         Some(api_method) => {
-            let description = wrap_text("", "", &api_method.parameters.description(), 80);
+            let description = wrap_text("", "", api_method.parameters.description(), 80);
             let param_descr = dump_properties(&api_method.parameters, "", style, &[]);
 
             let return_descr = dump_api_return_schema(&api_method.returns, style);
index eb93b3328f5703725a68fcb36d1b84df00fc395e..f2e9d4698100a6899337204d9bed6fda0cd8babb 100644 (file)
@@ -96,7 +96,7 @@ pub fn check_api_permission(
     param: &HashMap<String, String>,
     info: &dyn UserInformation,
 ) -> bool {
-    if let Some(ref userid) = userid {
+    if let Some(userid) = userid {
         if info.is_superuser(userid) {
             return true;
         }
@@ -120,7 +120,7 @@ fn check_api_permission_tail(
         }
         Permission::Superuser => match userid {
             None => return false,
-            Some(ref userid) => return info.is_superuser(userid),
+            Some(userid) => return info.is_superuser(userid),
         },
         Permission::User(expected_userid) => match userid {
             None => return false,
@@ -133,7 +133,7 @@ fn check_api_permission_tail(
         },
         Permission::Group(expected_group) => match userid {
             None => return false,
-            Some(ref userid) => return info.is_group_member(userid, expected_group),
+            Some(userid) => return info.is_group_member(userid, expected_group),
         },
         Permission::WithParam(param_name, subtest) => {
             return check_api_permission(
index 27c71984a24c5c4d6ea45025e93d1d1318546c11..7f7d7f9ba04fd37f5ad08bd19ca51f594dc56b1b 100644 (file)
@@ -60,14 +60,14 @@ pub enum RpcEnvironmentType {
 impl core::ops::Index<&str> for &dyn RpcEnvironment {
     type Output = Value;
     fn index(&self, index: &str) -> &Value {
-        &self.result_attrib().index(index)
+        self.result_attrib().index(index)
     }
 }
 
 impl core::ops::Index<&str> for &mut dyn RpcEnvironment {
     type Output = Value;
     fn index(&self, index: &str) -> &Value {
-        &self.result_attrib().index(index)
+        self.result_attrib().index(index)
     }
 }
 
index 104b1c0856536d01af14fb511ce83232ae20eeda..95cb76ce7510f3edff13fd3d4bf9ac5c679bfdaf 100644 (file)
@@ -113,12 +113,12 @@ pub fn dump_properties(
     let mut optional_list: Vec<String> = Vec::new();
 
     for (prop, optional, schema) in param.properties() {
-        if skip.iter().find(|n| n == &prop).is_some() {
+        if skip.iter().any(|n| n == prop) {
             continue;
         }
 
         let mut param_descr =
-            get_property_description(prop, &schema, style, DocumentationFormat::ReST);
+            get_property_description(prop, schema, style, DocumentationFormat::ReST);
 
         if !indent.is_empty() {
             param_descr = format!("{}{}", indent, param_descr); // indent first line
index 5e6e818588c2919a9dfa466dfbe4f84abd9e5490..44f19984659fb3fbfdaef4e644910ea25218b879 100644 (file)
@@ -885,7 +885,7 @@ pub fn parse_property_string(value_str: &str, schema: &'static Schema) -> Result
                 .collect();
 
             for value in list {
-                match parse_simple_value(value.trim(), &array_schema.items) {
+                match parse_simple_value(value.trim(), array_schema.items) {
                     Ok(res) => array.push(res),
                     Err(err) => bail!("unable to parse array element: {}", err),
                 }
@@ -951,7 +951,7 @@ fn do_parse_parameter_strings(
     let additional_properties = schema.additional_properties();
 
     for (key, value) in data {
-        if let Some((_optional, prop_schema)) = schema.lookup(&key) {
+        if let Some((_optional, prop_schema)) = schema.lookup(key) {
             match prop_schema {
                 Schema::Array(array_schema) => {
                     if params[key] == Value::Null {
@@ -959,7 +959,7 @@ fn do_parse_parameter_strings(
                     }
                     match params[key] {
                         Value::Array(ref mut array) => {
-                            match parse_simple_value(value, &array_schema.items) {
+                            match parse_simple_value(value, array_schema.items) {
                                 Ok(res) => array.push(res), // fixme: check_length??
                                 Err(err) => errors.push(key.into(), err),
                             }
@@ -1031,11 +1031,11 @@ pub fn verify_json(data: &Value, schema: &Schema) -> Result<(), Error> {
             }
         }
         Schema::Object(object_schema) => verify_json_object(data, object_schema)?,
-        Schema::Array(array_schema) => verify_json_array(data, &array_schema)?,
-        Schema::Boolean(boolean_schema) => verify_json_boolean(data, &boolean_schema)?,
-        Schema::Integer(integer_schema) => verify_json_integer(data, &integer_schema)?,
-        Schema::Number(number_schema) => verify_json_number(data, &number_schema)?,
-        Schema::String(string_schema) => verify_json_string(data, &string_schema)?,
+        Schema::Array(array_schema) => verify_json_array(data, array_schema)?,
+        Schema::Boolean(boolean_schema) => verify_json_boolean(data, boolean_schema)?,
+        Schema::Integer(integer_schema) => verify_json_integer(data, integer_schema)?,
+        Schema::Number(number_schema) => verify_json_number(data, number_schema)?,
+        Schema::String(string_schema) => verify_json_string(data, string_schema)?,
         Schema::AllOf(all_of_schema) => verify_json_object(data, all_of_schema)?,
     }
     Ok(())
@@ -1087,7 +1087,7 @@ pub fn verify_json_array(data: &Value, schema: &ArraySchema) -> Result<(), Error
     schema.check_length(list.len())?;
 
     for (i, item) in list.iter().enumerate() {
-        let result = verify_json(item, &schema.items);
+        let result = verify_json(item, schema.items);
         if let Err(err) = result {
             let mut errors = ParameterError::new();
             errors.add_errors(&format!("[{}]", i), err);
@@ -1111,7 +1111,7 @@ pub fn verify_json_object(data: &Value, schema: &dyn ObjectSchemaType) -> Result
     let additional_properties = schema.additional_properties();
 
     for (key, value) in map {
-        if let Some((_optional, prop_schema)) = schema.lookup(&key) {
+        if let Some((_optional, prop_schema)) = schema.lookup(key) {
             let result = match prop_schema {
                 Schema::Object(object_schema) => verify_json_object(value, object_schema),
                 Schema::Array(array_schema) => verify_json_array(value, array_schema),
index 36c63cc7b89028370a83e549a3af252271acfa55..592c203e53c2b00f33914706b6a4ec13c9b65b0b 100644 (file)
@@ -66,7 +66,7 @@ impl SectionConfigPlugin {
     pub fn get_id_schema(&self) -> Option<&Schema> {
         match &self.id_property {
             Some(id_prop) => {
-                if let Some((_, schema)) = self.properties.lookup(&id_prop) {
+                if let Some((_, schema)) = self.properties.lookup(id_prop) {
                     Some(schema)
                 } else {
                     None
@@ -325,7 +325,7 @@ impl SectionConfig {
             let plugin = self.plugins.get(type_name).unwrap();
 
             let id_schema = plugin.get_id_schema().unwrap_or(self.id_schema);
-            if let Err(err) = parse_simple_value(&section_id, &id_schema) {
+            if let Err(err) = parse_simple_value(section_id, id_schema) {
                 bail!("syntax error in section identifier: {}", err.to_string());
             }
             if section_id.chars().any(|c| c.is_control()) {
@@ -402,7 +402,7 @@ impl SectionConfig {
                                 (self.parse_section_header)(line)
                             {
                                 //println!("OKLINE: type: {} ID: {}", section_type, section_id);
-                                if let Some(ref plugin) = self.plugins.get(&section_type) {
+                                if let Some(plugin) = self.plugins.get(&section_type) {
                                     let id_schema =
                                         plugin.get_id_schema().unwrap_or(self.id_schema);
                                     if let Err(err) = parse_simple_value(&section_id, id_schema) {
@@ -480,12 +480,12 @@ impl SectionConfig {
                 if let ParseState::InsideSection(plugin, ref mut section_id, ref mut config) = state
                 {
                     // finish section
-                    test_required_properties(&config, plugin.properties, &plugin.id_property)?;
+                    test_required_properties(config, plugin.properties, &plugin.id_property)?;
                     if let Some(id_property) = &plugin.id_property {
                         config[id_property] = Value::from(section_id.clone());
                     }
-                    result.set_data(&section_id, &plugin.type_name, config)?;
-                    result.record_order(&section_id);
+                    result.set_data(section_id, &plugin.type_name, config)?;
+                    result.record_order(section_id);
                 }
 
                 Ok(())
@@ -756,7 +756,7 @@ lvmthin: local-lvm2
         content rootdir,images
 ";
 
-    let res = config.parse(filename, &raw);
+    let res = config.parse(filename, raw);
     println!("RES: {:?}", res);
     let raw = config.write(filename, &res.unwrap());
     println!("CONFIG:\n{}", raw.unwrap());
@@ -827,7 +827,7 @@ group: mygroup
         comment a very important group
 ";
 
-    let res = config.parse(filename, &raw);
+    let res = config.parse(filename, raw);
     println!("RES: {:?}", res);
     let raw = config.write(filename, &res.unwrap());
     println!("CONFIG:\n{}", raw.unwrap());
@@ -876,7 +876,7 @@ lvmthin: local-lvm2
        thinpool data
 ";
 
-    let res = config.parse(filename, &raw);
+    let res = config.parse(filename, raw);
     println!("RES: {:?}", res);
     let created = config
         .write(filename, &res.unwrap())