refactor: improve code based on clippy

This commit is contained in:
Marc-Antoine Arnaud
2023-12-19 22:15:43 +01:00
parent 568de4e1f0
commit a9b7aa2546
12 changed files with 39 additions and 125 deletions

View File

@@ -175,6 +175,7 @@ impl YaSerdeField {
}
#[derive(Debug)]
#[allow(clippy::enum_variant_names)]
pub enum Field {
FieldString,
FieldBool,

View File

@@ -199,17 +199,17 @@ pub fn parse(
.iter()
.map(|field| YaSerdeField::new(field.clone()))
.filter(|field| !field.is_attribute() && field.is_flatten())
.filter_map(|field| {
.map(|field| {
let value_label = field.get_value_label();
match field.get_type() {
Field::FieldStruct { .. } => Some(quote! {
Field::FieldStruct { .. } => quote! {
#value_label = ::yaserde::de::from_str(&unused_xml_elements)?;
}),
},
Field::FieldOption { data_type } => match *data_type {
Field::FieldStruct { .. } => Some(quote! {
Field::FieldStruct { .. } => quote! {
#value_label = ::yaserde::de::from_str(&unused_xml_elements).ok();
}),
},
field_type => unimplemented!(r#""flatten" is not implemented for {:?}"#, field_type),
},
field_type => unimplemented!(r#""flatten" is not implemented for {:?}"#, field_type),

View File

@@ -33,7 +33,6 @@ pub fn serialize(
let attribute_fields: Vec<_> = all_fields
.clone()
.into_iter()
.filter(|field| {
field.is_attribute()
|| (field.is_flatten() && matches!(field.get_type(), Field::FieldStruct { .. }))