From 9079afc831449a23a44ba7ed9965ef1b24882b22 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 31 May 2022 09:42:25 +0200 Subject: [PATCH] schema: clippy fixups Signed-off-by: Wolfgang Bumiller --- proxmox-schema/src/format.rs | 16 +++++++++++----- proxmox-schema/src/schema.rs | 4 +++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/proxmox-schema/src/format.rs b/proxmox-schema/src/format.rs index 65ae6dac..0246b728 100644 --- a/proxmox-schema/src/format.rs +++ b/proxmox-schema/src/format.rs @@ -5,7 +5,7 @@ use anyhow::{bail, Error}; use crate::*; /// Enumerate different styles to display parameters/properties. -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Eq)] pub enum ParameterDisplayStyle { /// Used for properties in configuration files: ``key:`` Config, @@ -18,7 +18,7 @@ pub enum ParameterDisplayStyle { } /// CLI usage information format. -#[derive(Copy, Clone, PartialEq)] +#[derive(Copy, Clone, PartialEq, Eq)] pub enum DocumentationFormat { /// Text, command line only (one line). Short, @@ -122,7 +122,7 @@ pub fn dump_properties( if !indent.is_empty() { param_descr = format!("{}{}", indent, param_descr); // indent first line - param_descr = param_descr.replace("\n", &format!("\n{}", indent)); // indent rest + param_descr = param_descr.replace('\n', &format!("\n{}", indent)); // indent rest } if style == ParameterDisplayStyle::Config { @@ -398,7 +398,10 @@ pub fn dump_enum_properties(schema: &Schema) -> Result { }) = schema { for item in variants.iter() { - res.push_str(&format!(":``{}``: ", item.value)); + use std::fmt::Write; + + let _ = write!(res, ":``{}``: ", item.value); + //res.push_str(&format!(":``{}``: ", item.value)); let descr = wrap_text("", " ", item.description, 80); res.push_str(&descr); res.push('\n'); @@ -410,6 +413,8 @@ pub fn dump_enum_properties(schema: &Schema) -> Result { } pub fn dump_api_return_schema(returns: &ReturnType, style: ParameterDisplayStyle) -> String { + use std::fmt::Write; + let schema = &returns.schema; let mut res = if returns.optional { @@ -419,7 +424,8 @@ pub fn dump_api_return_schema(returns: &ReturnType, style: ParameterDisplayStyle }; let type_text = get_schema_type_text(schema, style); - res.push_str(&format!("**{}**\n\n", type_text)); + //res.push_str(&format!("**{}**\n\n", type_text)); + let _ = write!(res, "**{}**\n\n", type_text); match schema { Schema::Null => { diff --git a/proxmox-schema/src/schema.rs b/proxmox-schema/src/schema.rs index 10d02b17..a2b165c8 100644 --- a/proxmox-schema/src/schema.rs +++ b/proxmox-schema/src/schema.rs @@ -92,6 +92,8 @@ impl ParameterError { impl fmt::Display for ParameterError { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + use std::fmt::Write; + let mut msg = String::new(); if !self.is_empty() { @@ -99,7 +101,7 @@ impl fmt::Display for ParameterError { } for (name, err) in self.error_list.iter() { - msg.push_str(&format!("parameter '{}': {}\n", name, err)); + let _ = writeln!(msg, "parameter '{}': {}", name, err); } write!(f, "{}", msg)