From c911279df32dfa9a7c4b69f833160ab6b498cc6c Mon Sep 17 00:00:00 2001 From: Will Hedgecock Date: Wed, 2 Oct 2024 00:18:14 -0500 Subject: [PATCH] Change vec references to slices --- musicxml/src/datatypes/pedal_type.rs | 2 +- musicxml/src/datatypes/xlink_type.rs | 2 +- musicxml/src/elements/arrow.rs | 2 +- musicxml/src/elements/credit.rs | 4 +- musicxml/src/elements/direction_type.rs | 2 +- musicxml/src/elements/glyph.rs | 2 +- musicxml/src/elements/grace.rs | 2 +- musicxml/src/elements/harmony.rs | 2 +- musicxml/src/elements/interchangeable.rs | 2 +- musicxml/src/elements/key.rs | 2 +- musicxml/src/elements/lyric.rs | 4 +- musicxml/src/elements/metronome.rs | 6 +- musicxml/src/elements/notations.rs | 2 +- musicxml/src/elements/note.rs | 12 +-- musicxml/src/elements/ornaments.rs | 2 +- musicxml/src/elements/part_list.rs | 2 +- musicxml/src/elements/time.rs | 2 +- musicxml/src/elements/wavy_line.rs | 2 +- musicxml_internal/src/lib.rs | 4 +- musicxml_macros/src/lib.rs | 112 ++++++++++------------- 20 files changed, 76 insertions(+), 94 deletions(-) diff --git a/musicxml/src/datatypes/pedal_type.rs b/musicxml/src/datatypes/pedal_type.rs index 13fcc46..9c5dc0d 100644 --- a/musicxml/src/datatypes/pedal_type.rs +++ b/musicxml/src/datatypes/pedal_type.rs @@ -7,7 +7,7 @@ use musicxml_macros::{DatatypeDeserialize, DatatypeSerialize}; pub enum PedalType { /// Indicates the start of a damper pedal. Start, - /// Indicates a pedal lift without a retake. + /// Indicates a pedal lift without a retake. Stop, /// Indicates the start of a sostenuto pedal. Sostenuto, diff --git a/musicxml/src/datatypes/xlink_type.rs b/musicxml/src/datatypes/xlink_type.rs index e2595ae..1f54e29 100644 --- a/musicxml/src/datatypes/xlink_type.rs +++ b/musicxml/src/datatypes/xlink_type.rs @@ -7,6 +7,6 @@ use musicxml_macros::{DatatypeDeserialize, DatatypeSerialize}; /// MusicXML only supports the simple type. #[derive(Debug, PartialEq, Eq, DatatypeDeserialize, DatatypeSerialize)] pub enum XlinkType { - /// See the definition in the [XML Linking Language recommendation](https://www.w3.org/TR/xlink11/#dt-simplelink). + /// See the definition in the [XML Linking Language recommendation](https://www.w3.org/TR/xlink11/#dt-simplelink). Simple, } diff --git a/musicxml/src/elements/arrow.rs b/musicxml/src/elements/arrow.rs index 858e1dc..b2a4178 100644 --- a/musicxml/src/elements/arrow.rs +++ b/musicxml/src/elements/arrow.rs @@ -73,7 +73,7 @@ pub enum ArrowContents { } impl ContentDeserializer for ArrowContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { if let Some(_) = elements.iter().find(|&el| el.name == "circular-arrow") { Ok(ArrowContents::Circular(CircularArrowContents::deserialize(elements)?)) } else { diff --git a/musicxml/src/elements/credit.rs b/musicxml/src/elements/credit.rs index ca5ffc9..4722d5c 100644 --- a/musicxml/src/elements/credit.rs +++ b/musicxml/src/elements/credit.rs @@ -48,7 +48,7 @@ pub struct CreditTextContents { } impl ContentDeserializer for CreditTextContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut subcontents: Option = None; let mut contents = CreditTextContents::default(); for element in elements { @@ -112,7 +112,7 @@ pub struct CreditContents { } impl ContentDeserializer for CreditContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut contents = CreditContents { credit_type: Vec::new(), link: Vec::new(), diff --git a/musicxml/src/elements/direction_type.rs b/musicxml/src/elements/direction_type.rs index e34e699..2da7a9b 100644 --- a/musicxml/src/elements/direction_type.rs +++ b/musicxml/src/elements/direction_type.rs @@ -69,7 +69,7 @@ pub enum DirectionTypeContents { } impl ContentDeserializer for DirectionTypeContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { Ok(if let Some(element) = elements.first() { match element.name.as_str() { "rehearsal" => DirectionTypeContents::Rehearsal( diff --git a/musicxml/src/elements/glyph.rs b/musicxml/src/elements/glyph.rs index 948e917..8e9343a 100644 --- a/musicxml/src/elements/glyph.rs +++ b/musicxml/src/elements/glyph.rs @@ -6,7 +6,7 @@ use musicxml_macros::*; /// Attributes pertaining to the [Glyph] element. #[derive(Debug, PartialEq, Eq, AttributeDeserialize, AttributeSerialize)] pub struct GlyphAttributes { - /// The type of glyph that is being defined. + /// The type of glyph that is being defined. pub r#type: GlyphType, } diff --git a/musicxml/src/elements/grace.rs b/musicxml/src/elements/grace.rs index b4f9a0c..b370652 100644 --- a/musicxml/src/elements/grace.rs +++ b/musicxml/src/elements/grace.rs @@ -9,7 +9,7 @@ pub struct GraceAttributes { /// Indicates to make time, not steal time, for grace note playback. /// The units are in real-time divisions for the grace note. pub make_time: Option, - /// The value is yes for slashed grace notes and no if no slash is present. + /// The value is yes for slashed grace notes and no if no slash is present. pub slash: Option, /// Indicates the percentage of time to steal from the following note for the grace note playback, as for appoggiaturas. pub steal_time_following: Option, diff --git a/musicxml/src/elements/harmony.rs b/musicxml/src/elements/harmony.rs index 9b528c3..80046d7 100644 --- a/musicxml/src/elements/harmony.rs +++ b/musicxml/src/elements/harmony.rs @@ -97,7 +97,7 @@ pub struct HarmonyContents { } impl ContentDeserializer for HarmonyContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut harmony: Vec = Vec::new(); for element in elements { if element.name == "root" || element.name == "numeral" || element.name == "function" { diff --git a/musicxml/src/elements/interchangeable.rs b/musicxml/src/elements/interchangeable.rs index b6fe73b..baf5e08 100644 --- a/musicxml/src/elements/interchangeable.rs +++ b/musicxml/src/elements/interchangeable.rs @@ -32,7 +32,7 @@ pub struct InterchangeableContents { } impl ContentDeserializer for InterchangeableContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut temp_beats: Option = None; let mut time_relation = None; let mut beat_data = Vec::new(); diff --git a/musicxml/src/elements/key.rs b/musicxml/src/elements/key.rs index 6bafbe9..8d8e05c 100644 --- a/musicxml/src/elements/key.rs +++ b/musicxml/src/elements/key.rs @@ -82,7 +82,7 @@ pub enum KeyContents { } impl ContentDeserializer for KeyContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { Ok(if let Some(_) = elements.iter().find(|&el| el.name == "fifths") { KeyContents::Explicit(ExplicitKeyContents::deserialize(elements)?) } else { diff --git a/musicxml/src/elements/lyric.rs b/musicxml/src/elements/lyric.rs index 142c851..af5b88e 100644 --- a/musicxml/src/elements/lyric.rs +++ b/musicxml/src/elements/lyric.rs @@ -80,7 +80,7 @@ pub struct TextLyric { } impl ContentDeserializer for TextLyric { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut text_lyric = TextLyric::default(); for el in elements { match el.name.as_str() { @@ -223,7 +223,7 @@ pub enum LyricContents { } impl ContentDeserializer for LyricContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { Ok(if let Some(_) = elements.iter().find(|&el| el.name == "text") { LyricContents::Text(TextLyric::deserialize(elements)?) } else if let Some(_) = elements.iter().find(|&el| el.name == "laughing") { diff --git a/musicxml/src/elements/metronome.rs b/musicxml/src/elements/metronome.rs index 4d7cc89..cfcaad6 100644 --- a/musicxml/src/elements/metronome.rs +++ b/musicxml/src/elements/metronome.rs @@ -99,7 +99,7 @@ pub struct BeatBased { } impl ContentDeserializer for BeatBased { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut beat_unit: Option = None; let mut beat_unit_dot: Vec = Vec::new(); let mut beat_unit_tied: Vec = Vec::new(); @@ -203,7 +203,7 @@ pub struct MetronomeBased { } impl ContentDeserializer for MetronomeBased { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut content = MetronomeBased::default(); for element in elements { match element.name.as_str() { @@ -261,7 +261,7 @@ pub enum MetronomeContents { } impl ContentDeserializer for MetronomeContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { Ok( if let Some(_) = elements.iter().find(|&el| el.name == "metronome-note") { MetronomeContents::MetronomeBased(MetronomeBased::deserialize(elements)?) diff --git a/musicxml/src/elements/notations.rs b/musicxml/src/elements/notations.rs index 8b9dc87..c1c137f 100644 --- a/musicxml/src/elements/notations.rs +++ b/musicxml/src/elements/notations.rs @@ -61,7 +61,7 @@ pub struct NotationsContents { } impl ContentDeserializer for NotationsContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut notations = NotationsContents::default(); for child in elements { match child.name.as_str() { diff --git a/musicxml/src/elements/note.rs b/musicxml/src/elements/note.rs index 5d83fd2..78c2720 100644 --- a/musicxml/src/elements/note.rs +++ b/musicxml/src/elements/note.rs @@ -101,7 +101,7 @@ pub struct GraceNormalInfo { } impl ContentDeserializer for GraceNormalInfo { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut chord: Option = None; let mut audible: Option = None; let mut tie: Vec = Vec::new(); @@ -157,7 +157,7 @@ pub struct GraceCueInfo { } impl ContentDeserializer for GraceCueInfo { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut cue: Option = None; let mut chord: Option = None; let mut audible: Option = None; @@ -222,7 +222,7 @@ pub struct GraceInfo { } impl ContentDeserializer for GraceInfo { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { Ok(GraceInfo { grace: Grace::deserialize(elements.first().unwrap())?, info: if elements.iter().find(|&el| el.name == "cue").is_some() { @@ -260,7 +260,7 @@ pub struct CueInfo { } impl ContentDeserializer for CueInfo { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut cue: Option = None; let mut chord: Option = None; let mut audible: Option = None; @@ -328,7 +328,7 @@ pub struct NormalInfo { } impl ContentDeserializer for NormalInfo { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut chord: Option = None; let mut audible: Option = None; let mut duration: Option = None; @@ -433,7 +433,7 @@ pub struct NoteContents { } impl ContentDeserializer for NoteContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut note_contents = NoteContents { info: if elements.first().unwrap().name == "grace" { NoteType::Grace(GraceInfo::deserialize(elements)?) diff --git a/musicxml/src/elements/ornaments.rs b/musicxml/src/elements/ornaments.rs index fab5bdb..8ebd065 100644 --- a/musicxml/src/elements/ornaments.rs +++ b/musicxml/src/elements/ornaments.rs @@ -68,7 +68,7 @@ pub struct OrnamentContents { } impl ContentDeserializer for OrnamentContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { Ok(OrnamentContents { ornaments: elements .iter() diff --git a/musicxml/src/elements/part_list.rs b/musicxml/src/elements/part_list.rs index a14bf03..b2bccf9 100644 --- a/musicxml/src/elements/part_list.rs +++ b/musicxml/src/elements/part_list.rs @@ -20,7 +20,7 @@ pub struct PartListContents { } impl ContentDeserializer for PartListContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut content = PartListContents { content: Vec::new() }; for element in elements { if element.name == "part-group" { diff --git a/musicxml/src/elements/time.rs b/musicxml/src/elements/time.rs index bb8f1e7..804475c 100644 --- a/musicxml/src/elements/time.rs +++ b/musicxml/src/elements/time.rs @@ -87,7 +87,7 @@ pub struct TimeContents { } impl ContentDeserializer for TimeContents { - fn deserialize(elements: &Vec) -> Result { + fn deserialize(elements: &[XmlElement]) -> Result { let mut beats = Vec::new(); let mut time_beats = None; let mut interchangeable = None; diff --git a/musicxml/src/elements/wavy_line.rs b/musicxml/src/elements/wavy_line.rs index ad6efdb..e882440 100644 --- a/musicxml/src/elements/wavy_line.rs +++ b/musicxml/src/elements/wavy_line.rs @@ -11,7 +11,7 @@ use musicxml_macros::*; pub struct WavyLineAttributes { /// Indicates if this is the start, stop, or continuation of the wavy line. The value should be continue whenever used within a [Barline][super::Barline] element. pub r#type: StartStopContinue, - /// If yes, the trill accelerates during playback. It is no if not specified. + /// If yes, the trill accelerates during playback. It is no if not specified. pub acclerate: Option, /// The number of distinct notes during playback, counting the starting note but not the two-note turn. It is 4 if not specified. pub beats: Option, diff --git a/musicxml_internal/src/lib.rs b/musicxml_internal/src/lib.rs index 39db3a5..ad68234 100644 --- a/musicxml_internal/src/lib.rs +++ b/musicxml_internal/src/lib.rs @@ -18,11 +18,11 @@ pub trait DatatypeDeserializer: Sized { } pub trait AttributeDeserializer: Sized { - fn deserialize(attributes: &Vec<(String, String)>) -> Result; + fn deserialize(attributes: &[(String, String)]) -> Result; } pub trait ContentDeserializer: Sized { - fn deserialize(elements: &Vec) -> Result; + fn deserialize(elements: &[XmlElement]) -> Result; } pub trait ElementDeserializer: Sized { diff --git a/musicxml_macros/src/lib.rs b/musicxml_macros/src/lib.rs index 3ffbed9..e9827b4 100644 --- a/musicxml_macros/src/lib.rs +++ b/musicxml_macros/src/lib.rs @@ -141,7 +141,7 @@ pub fn deserialize_datatype(tokens: TokenStream) -> TokenStream { _ => panic!("Unit structs are not supported in MusicXML"), }, syn::Data::Enum(data) => deserialize_datatype_enum(&ast.ident, data), - _ => panic!("Unions are unsupported in MusicXML datatypes"), + syn::Data::Union(_) => panic!("Unions are unsupported in MusicXML datatypes"), } } @@ -154,7 +154,7 @@ pub fn serialize_datatype(tokens: TokenStream) -> TokenStream { _ => panic!("Unit structs are not supported in MusicXML"), }, syn::Data::Enum(data) => serialize_datatype_enum(&ast.ident, data), - _ => panic!("Unions are unsupported in MusicXML datatypes"), + syn::Data::Union(_) => panic!("Unions are unsupported in MusicXML datatypes"), } } @@ -174,7 +174,7 @@ fn deserialize_attribute_named_struct(element_type: &syn::Ident, fields: &syn::F .to_string() .replace("xml_", "xml:") .replace("xlink_", "xlink:") - .replace("_", "-") + .replace('_', "-") .replace("r#", ""); // Deserialize field based on its type @@ -184,15 +184,13 @@ fn deserialize_attribute_named_struct(element_type: &syn::Ident, fields: &syn::F match &field_details.ident { field_type if field_type == "Option" => { if let syn::PathArguments::AngleBracketed(details) = &field_details.arguments { - if let syn::GenericArgument::Type(option_type) = details.args.first().unwrap() { - if let syn::Type::Path(option_path) = option_type { - deserialized_fields.push(quote! { - #field_name: match attributes.iter().find(|&el| el.0 == #field_name_string) { - Some(attr) => Some(#option_path::deserialize(attr.1.as_str())?), - None => None, - } - }); - } + if let syn::GenericArgument::Type(syn::Type::Path(option_path)) = details.args.first().unwrap() { + deserialized_fields.push(quote! { + #field_name: match attributes.iter().find(|&el| el.0 == #field_name_string) { + Some(attr) => Some(#option_path::deserialize(attr.1.as_str())?), + None => None, + } + }); } } } @@ -213,7 +211,7 @@ fn deserialize_attribute_named_struct(element_type: &syn::Ident, fields: &syn::F // Generate the actual deserialization function TokenStream::from(quote! { impl AttributeDeserializer for #element_type { - fn deserialize(attributes: &Vec<(String, String)>) -> Result<#element_type, String> { + fn deserialize(attributes: &[(String, String)]) -> Result<#element_type, String> { Ok(#element_type { #(#deserialized_fields),* }) } } @@ -232,7 +230,7 @@ fn serialize_attribute_named_struct(element_type: &syn::Ident, fields: &syn::Fie .replace("xml_", "xml:") .replace("xlink_", "xlink:") .replace("r#", "") - .replace("_", "-"); + .replace('_', "-"); // Serialize field based on its type match &field.ty { @@ -241,14 +239,12 @@ fn serialize_attribute_named_struct(element_type: &syn::Ident, fields: &syn::Fie match &field_details.ident { field_type if field_type == "Option" => { if let syn::PathArguments::AngleBracketed(details) = &field_details.arguments { - if let syn::GenericArgument::Type(option_type) = details.args.first().unwrap() { - if let syn::Type::Path(option_path) = option_type { - serialized_fields.push(quote! { - if let Some(data) = &element.#field_name { - attributes.push((String::from(#field_name_string), #option_path::serialize(data))); - } - }); - } + if let syn::GenericArgument::Type(syn::Type::Path(option_path)) = details.args.first().unwrap() { + serialized_fields.push(quote! { + if let Some(data) = &element.#field_name { + attributes.push((String::from(#field_name_string), #option_path::serialize(data))); + } + }); } } } @@ -309,7 +305,7 @@ fn deserialize_content_named_struct(element_type: &syn::Ident, fields: &syn::Fie for field in &fields.named { // Perform any requested field renaming let field_name = field.ident.as_ref().unwrap(); - let field_name_string = field_name.to_string().replace("_", "-"); + let field_name_string = field_name.to_string().replace('_', "-"); // Deserialize field based on its type match &field.ty { @@ -318,24 +314,20 @@ fn deserialize_content_named_struct(element_type: &syn::Ident, fields: &syn::Fie match &field_details.ident { field_type if field_type == "Option" => { if let syn::PathArguments::AngleBracketed(details) = &field_details.arguments { - if let syn::GenericArgument::Type(option_type) = details.args.first().unwrap() { - if let syn::Type::Path(option_path) = option_type { - deserialized_fields.push(quote! { - #field_name: match elements.iter().find(|&el| el.name == #field_name_string) { - Some(element) => Some(#option_path::deserialize(element)?), - None => None, - } - }); - } + if let syn::GenericArgument::Type(syn::Type::Path(option_path)) = details.args.first().unwrap() { + deserialized_fields.push(quote! { + #field_name: match elements.iter().find(|&el| el.name == #field_name_string) { + Some(element) => Some(#option_path::deserialize(element)?), + None => None, + } + }); } } } field_type if field_type == "Vec" => { if let syn::PathArguments::AngleBracketed(details) = &field_details.arguments { - if let syn::GenericArgument::Type(vec_type) = details.args.first().unwrap() { - if let syn::Type::Path(vec_path) = vec_type { - deserialized_fields.push(quote! { #field_name: elements.iter().filter_map(|el| if el.name == #field_name_string { #vec_path::deserialize(el).ok() } else { None }).collect::>() }); - } + if let syn::GenericArgument::Type(syn::Type::Path(vec_path)) = details.args.first().unwrap() { + deserialized_fields.push(quote! { #field_name: elements.iter().filter_map(|el| if el.name == #field_name_string { #vec_path::deserialize(el).ok() } else { None }).collect::>() }); } } } @@ -351,7 +343,7 @@ fn deserialize_content_named_struct(element_type: &syn::Ident, fields: &syn::Fie // Generate the actual deserialization function TokenStream::from(quote! { impl ContentDeserializer for #element_type { - fn deserialize(elements: &Vec) -> Result<#element_type, String> { + fn deserialize(elements: &[XmlElement]) -> Result<#element_type, String> { Ok(#element_type { #(#deserialized_fields),* }) } } @@ -374,23 +366,19 @@ fn serialize_content_named_struct(element_type: &syn::Ident, fields: &syn::Field match &field_details.ident { field_type if field_type == "Option" => { if let syn::PathArguments::AngleBracketed(details) = &field_details.arguments { - if let syn::GenericArgument::Type(option_type) = details.args.first().unwrap() { - if let syn::Type::Path(option_path) = option_type { - serialized_fields.push(quote! { - if let Some(data) = &element.#field_name { elements.push(#option_path::serialize(data)); } - }); - } + if let syn::GenericArgument::Type(syn::Type::Path(option_path)) = details.args.first().unwrap() { + serialized_fields.push(quote! { + if let Some(data) = &element.#field_name { elements.push(#option_path::serialize(data)); } + }); } } } field_type if field_type == "Vec" => { if let syn::PathArguments::AngleBracketed(details) = &field_details.arguments { - if let syn::GenericArgument::Type(vec_type) = details.args.first().unwrap() { - if let syn::Type::Path(vec_path) = vec_type { - serialized_fields.push(quote! { - for child in &element.#field_name { elements.push(#vec_path::serialize(child)); } - }); - } + if let syn::GenericArgument::Type(syn::Type::Path(vec_path)) = details.args.first().unwrap() { + serialized_fields.push(quote! { + for child in &element.#field_name { elements.push(#vec_path::serialize(child)); } + }); } } } @@ -558,10 +546,8 @@ fn deserialize_element_named_struct(element_type: &syn::Ident, fields: &syn::Fie match &field_details.ident { field_type if field_type == "Vec" => { if let syn::PathArguments::AngleBracketed(details) = &field_details.arguments { - if let syn::GenericArgument::Type(vec_type) = details.args.first().unwrap() { - if let syn::Type::Path(vec_path) = vec_type { - deserialized_fields.push(quote! { #field_name: element.elements.iter().filter_map(|el| #vec_path::deserialize(el).ok()).collect::>() }); - } + if let syn::GenericArgument::Type(syn::Type::Path(vec_path)) = details.args.first().unwrap() { + deserialized_fields.push(quote! { #field_name: element.elements.iter().filter_map(|el| #vec_path::deserialize(el).ok()).collect::>() }); } } } @@ -571,8 +557,7 @@ fn deserialize_element_named_struct(element_type: &syn::Ident, fields: &syn::Fie } else if field .attrs .iter() - .find(|&attr| attr.path().is_ident("flatten")) - .is_some() + .any(|attr| attr.path().is_ident("flatten")) { deserialized_fields.push(quote! { #field_name: #type_path::deserialize(&element.elements)? }); } else { @@ -614,12 +599,10 @@ fn serialize_element_named_struct( match &field_details.ident { field_type if field_type == "Vec" => { if let syn::PathArguments::AngleBracketed(details) = &field_details.arguments { - if let syn::GenericArgument::Type(vec_type) = details.args.first().unwrap() { - if let syn::Type::Path(vec_path) = vec_type { - serialized_fields.push( - quote! { elements: element.content.iter().map(|el| #vec_path::serialize(el)).collect::>() }, - ); - } + if let syn::GenericArgument::Type(syn::Type::Path(vec_path)) = details.args.first().unwrap() { + serialized_fields.push( + quote! { elements: element.content.iter().map(|el| #vec_path::serialize(el)).collect::>() }, + ); } } } @@ -629,8 +612,7 @@ fn serialize_element_named_struct( } else if field .attrs .iter() - .find(|&attr| attr.path().is_ident("flatten")) - .is_some() + .any(|attr| attr.path().is_ident("flatten")) { serialized_fields.push(quote! { elements: #type_path::serialize(&element.content) }); } else { @@ -666,7 +648,7 @@ pub fn deserialize_element(tokens: TokenStream) -> TokenStream { _ => panic!("Unit and tuple structs are not supported in MusicXML elements"), }, syn::Data::Enum(data) => deserialize_element_enum(&ast.ident, data), - _ => panic!("Unions are unsupported in MusicXML elements"), + syn::Data::Union(_) => panic!("Unions are unsupported in MusicXML elements"), } } @@ -691,6 +673,6 @@ pub fn serialize_element(tokens: TokenStream) -> TokenStream { _ => panic!("Unit and tuple structs are not supported in MusicXML elements"), }, syn::Data::Enum(data) => serialize_element_enum(&ast.ident, data), - _ => panic!("Unions are unsupported in MusicXML elements"), + syn::Data::Union(_) => panic!("Unions are unsupported in MusicXML elements"), } }