From 787c6550d4d464bab17a6cd91c8fa460c36e7f41 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Wed, 9 Mar 2022 09:55:37 +0100 Subject: [PATCH] proxmox-backup-debug api: fewer cloning Signed-off-by: Wolfgang Bumiller --- src/bin/proxmox_backup_debug/api.rs | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/bin/proxmox_backup_debug/api.rs b/src/bin/proxmox_backup_debug/api.rs index ba2117e4..47124089 100644 --- a/src/bin/proxmox_backup_debug/api.rs +++ b/src/bin/proxmox_backup_debug/api.rs @@ -149,19 +149,23 @@ fn merge_parameters( param: Option, schema: ParameterSchema, ) -> Result { - let mut param_list: Vec<(String, String)> = vec![]; + let mut param_list: Vec<(String, String)> = uri_param + .iter() + .map(|(k, v)| (k.clone(), v.clone())) + .collect(); - for (k, v) in uri_param { - param_list.push((k.clone(), v.clone())); + if let Some(Value::Object(map)) = param { + param_list.extend(map.into_iter().map(|(k, v)| { + ( + k, + match v { + Value::String(s) => s, + _ => unreachable!(), // we're in the CLI + }, + ) + })); } - let param = param.unwrap_or(json!({})); - - if let Some(map) = param.as_object() { - for (k, v) in map { - param_list.push((k.clone(), v.as_str().unwrap().to_string())); - } - } let params = schema.parse_parameter_strings(¶m_list, true)?;