avoid some clippy warnings

This commit is contained in:
Dietmar Maurer
2019-10-26 11:36:01 +02:00
parent 834a2f95a0
commit 62ee2eb405
50 changed files with 179 additions and 246 deletions

View File

@ -38,9 +38,9 @@ pub fn wrap_text(initial_indent: &str, subsequent_indent: &str, text: &str, colu
text.split("\n\n")
.map(|p| p.trim())
.filter(|p| { p.len() != 0 })
.filter(|p| !p.is_empty())
.fold(String::new(), |mut acc, p| {
if acc.len() == 0 {
if acc.is_empty() {
acc.push_str(&wrapper1.wrap(p).concat());
} else {
acc.push_str(&wrapper2.wrap(p).concat());
@ -142,11 +142,11 @@ fn dump_api_parameters(param: &ObjectSchema) -> String {
let properties = &param.properties;
let mut prop_names: Vec<&str> = properties.keys().map(|v| *v).collect();
let mut prop_names: Vec<&str> = properties.keys().copied().collect();
prop_names.sort();
let mut required_list: Vec<String> = vec![];
let mut optional_list: Vec<String> = vec![];
let mut required_list: Vec<String> = Vec::new();
let mut optional_list: Vec<String> = Vec::new();
for prop in prop_names {
let (optional, schema) = properties.get(prop).unwrap();
@ -161,7 +161,7 @@ fn dump_api_parameters(param: &ObjectSchema) -> String {
}
}
if required_list.len() > 0 {
if !required_list.is_empty() {
res.push_str("\n*Required properties:*\n\n");
@ -172,7 +172,7 @@ fn dump_api_parameters(param: &ObjectSchema) -> String {
}
if optional_list.len() > 0 {
if !optional_list.is_empty() {
res.push_str("\n*Optional properties:*\n\n");

View File

@ -4,6 +4,7 @@ use failure::*;
use std::collections::HashMap;
use std::sync::Arc;
#[derive(Default)]
pub struct Registry {
formats: HashMap<&'static str, Arc<ApiStringFormat>>,
options: HashMap<&'static str, Arc<Schema>>,

View File

@ -284,7 +284,7 @@ impl Router {
pub fn find_route(&self, components: &[&str], uri_param: &mut HashMap<String, String>) -> Option<&Router> {
if components.len() == 0 { return Some(self); };
if components.is_empty() { return Some(self); };
let (dir, rest) = (components[0], &components[1..]);
@ -325,3 +325,9 @@ impl Router {
&MethodDefinition::None
}
}
impl Default for Router {
fn default() -> Self {
Self::new()
}
}

View File

@ -6,7 +6,7 @@ use regex::Regex;
use std::fmt;
use std::sync::Arc;
#[derive(Debug, Fail)]
#[derive(Default, Debug, Fail)]
pub struct ParameterError {
error_list: Vec<Error>,
}
@ -22,7 +22,7 @@ pub struct ParameterError {
impl ParameterError {
pub fn new() -> Self {
Self { error_list: vec![] }
Self { error_list: Vec::new() }
}
pub fn push(&mut self, value: Error) {
@ -32,6 +32,10 @@ impl ParameterError {
pub fn len(&self) -> usize {
self.error_list.len()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl fmt::Display for ParameterError {
@ -39,7 +43,7 @@ impl fmt::Display for ParameterError {
let mut msg = String::new();
if self.len() > 0 {
if !self.is_empty() {
msg.push_str("parameter verification errors\n\n");
}
@ -470,7 +474,7 @@ pub fn parse_simple_value(value_str: &str, schema: &Schema) -> Result<Value, Err
Ok(value)
}
pub fn parse_parameter_strings(data: &Vec<(String, String)>, schema: &ObjectSchema, test_required: bool) -> Result<Value, ParameterError> {
pub fn parse_parameter_strings(data: &[(String, String)], schema: &ObjectSchema, test_required: bool) -> Result<Value, ParameterError> {
let mut params = json!({});
@ -530,13 +534,13 @@ pub fn parse_parameter_strings(data: &Vec<(String, String)>, schema: &ObjectSche
if test_required && errors.len() == 0 {
for (name, (optional, _prop_schema)) in properties {
if *optional == false && params[name] == Value::Null {
if !(*optional) && params[name] == Value::Null {
errors.push(format_err!("parameter '{}': parameter is missing and it is not optional.", name));
}
}
}
if errors.len() > 0 {
if !errors.is_empty() {
Err(errors)
} else {
Ok(params)
@ -640,7 +644,7 @@ pub fn verify_json_object(data: &Value, schema: &ObjectSchema) -> Result<(), Err
}
for (name, (optional, _prop_schema)) in properties {
if *optional == false && data[name] == Value::Null {
if !(*optional) && data[name] == Value::Null {
bail!("property '{}': property is missing and it is not optional.", name);
}
}