Apply some clippy suggestions

This commit is contained in:
Graham Esau 2021-03-19 23:20:16 +00:00
parent b8c548136a
commit 3a7d7ad905
7 changed files with 15 additions and 22 deletions

View file

@ -27,10 +27,8 @@ pub enum MyEnum {
StructVariant { floats: Vec<f32> },
}
fn main() {
let schema = schema_for!(MyStruct);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
```
<details>
@ -133,10 +131,8 @@ pub enum MyEnum {
StructVariant { floats: Vec<f32> },
}
fn main() {
let schema = schema_for!(MyStruct);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
```
<details>

1
clippy.toml Normal file
View file

@ -0,0 +1 @@
msrv = "1.36.0"

View file

@ -335,8 +335,8 @@ impl SchemaGenerator {
#[doc(hidden)]
pub fn apply_metadata(&self, schema: Schema, metadata: Option<Metadata>) -> Schema {
match metadata {
None => return schema,
Some(ref metadata) if *metadata == Metadata::default() => return schema,
None => schema,
Some(ref metadata) if *metadata == Metadata::default() => schema,
Some(metadata) => {
let mut schema_obj = schema.into_object();
schema_obj.metadata = Some(Box::new(metadata)).merge(schema_obj.metadata);

View file

@ -22,10 +22,8 @@ pub enum MyEnum {
StructVariant { floats: Vec<f32> },
}
fn main() {
let schema = schema_for!(MyStruct);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
```
<details>
@ -128,10 +126,8 @@ pub enum MyEnum {
StructVariant { floats: Vec<f32> },
}
fn main() {
let schema = schema_for!(MyStruct);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
```
<details>

View file

@ -52,7 +52,7 @@ fn get_doc(attrs: &[Attribute]) -> Option<String> {
.iter()
.flat_map(|a| a.split('\n'))
.map(str::trim)
.skip_while(|s| *s == "")
.skip_while(|s| s.is_empty())
.collect::<Vec<_>>();
if let Some(&"") = lines.last() {
@ -61,7 +61,7 @@ fn get_doc(attrs: &[Attribute]) -> Option<String> {
// Added for backward-compatibility, but perhaps we shouldn't do this
// https://github.com/rust-lang/rust/issues/32088
if lines.iter().all(|l| l.starts_with("*")) {
if lines.iter().all(|l| l.starts_with('*')) {
for line in lines.iter_mut() {
*line = line[1..].trim()
}

View file

@ -105,7 +105,7 @@ impl<'a> SchemaMetadata<'a> {
}
}
fn none_if_empty<'a>(s: &'a String) -> Option<&'a str> {
fn none_if_empty(s: &String) -> Option<&str> {
if s.is_empty() {
None
} else {

View file

@ -98,7 +98,7 @@ fn expr_for_external_tagged_enum<'a>(
}
let mut schemas = Vec::new();
if unit_variants.len() > 0 {
if !unit_variants.is_empty() {
schemas.push(unit_schema);
}