Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Oct 2, 2024
1 parent 5e94f82 commit 93bcbb2
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 31 deletions.
4 changes: 1 addition & 3 deletions musicxml/src/datatypes/number_or_normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ impl DatatypeDeserializer for NumberOrNormal {
} else if value.to_lowercase() == "normal" {
Ok(NumberOrNormal::Normal)
} else {
Err(format!(
"Value {value} is invalid for the <number-or-normal> data type"
))
Err(format!("Value {value} is invalid for the <number-or-normal> data type"))
}
}
}
Expand Down
12 changes: 5 additions & 7 deletions musicxml/src/datatypes/time_only.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
use super::positive_integer::PositiveInteger;
use alloc::{string::{String, ToString}, vec::Vec};
use alloc::{
string::{String, ToString},
vec::Vec,
};
use core::ops::Deref;
use musicxml_internal::{DatatypeDeserializer, DatatypeSerializer};

Expand All @@ -22,12 +25,7 @@ impl Deref for TimeOnly {

impl DatatypeSerializer for TimeOnly {
fn serialize(element: &Self) -> String {
element
.0
.iter()
.map(ToString::to_string)
.collect::<Vec<_>>()
.join(",")
element.0.iter().map(ToString::to_string).collect::<Vec<_>>().join(",")
}
}

Expand Down
12 changes: 10 additions & 2 deletions musicxml/src/elements/credit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,16 @@ impl ContentDeserializer for CreditTextContents {
let mut contents = CreditTextContents::default();
for element in elements {
match element.name.as_str() {
"link" => if let Some(content) = subcontents.as_mut() { content.link.push(Link::deserialize(element)?) },
"bookmark" => if let Some(content) = subcontents.as_mut() { content.bookmark.push(Bookmark::deserialize(element)?) },
"link" => {
if let Some(content) = subcontents.as_mut() {
content.link.push(Link::deserialize(element)?)
}
}
"bookmark" => {
if let Some(content) = subcontents.as_mut() {
content.bookmark.push(Bookmark::deserialize(element)?)
}
}
"credit-words" => {
match subcontents {
Some(mut content) => {
Expand Down
12 changes: 5 additions & 7 deletions musicxml/src/elements/metronome.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,11 @@ pub enum MetronomeContents {

impl ContentDeserializer for MetronomeContents {
fn deserialize(elements: &[XmlElement]) -> Result<Self, String> {
Ok(
if elements.iter().any(|el| el.name == "metronome-note") {
MetronomeContents::MetronomeBased(MetronomeBased::deserialize(elements)?)
} else {
MetronomeContents::BeatBased(BeatBased::deserialize(elements)?)
},
)
Ok(if elements.iter().any(|el| el.name == "metronome-note") {
MetronomeContents::MetronomeBased(MetronomeBased::deserialize(elements)?)
} else {
MetronomeContents::BeatBased(BeatBased::deserialize(elements)?)
})
}
}

Expand Down
6 changes: 4 additions & 2 deletions musicxml/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,17 @@ fn get_musicxml_contents_from_file(path: &str) -> Result<String, String> {
.iter()
.find(|&el| el.name == "rootfiles")
.and_then(|el| el.elements.iter().find(|&el| el.name == "rootfile"))
.and_then(|el| el.attributes.iter().find(|&attr| attr.0 == "full-path")).map(|attr| attr.1.clone());
.and_then(|el| el.attributes.iter().find(|&attr| attr.0 == "full-path"))
.map(|attr| attr.1.clone());
}
}
if let Some(full_path) = &xml_path {
let file = archive
.get_file(full_path.as_str())
.ok_or("MXL file missing expected contents")?;
core::str::from_utf8(file.data.as_slice())
.map_err(|e| e.to_string())?.clone_into(&mut contents);
.map_err(|e| e.to_string())?
.clone_into(&mut contents);
} else {
Err(String::from("Cannot find MusicXML file in compressed archive"))?;
}
Expand Down
12 changes: 2 additions & 10 deletions musicxml_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -554,11 +554,7 @@ fn deserialize_element_named_struct(element_type: &syn::Ident, fields: &syn::Fie
_ => {
if field_name == "attributes" {
deserialized_fields.push(quote! { #field_name: #type_path::deserialize(&element.attributes)? });
} else if field
.attrs
.iter()
.any(|attr| attr.path().is_ident("flatten"))
{
} else if field.attrs.iter().any(|attr| attr.path().is_ident("flatten")) {
deserialized_fields.push(quote! { #field_name: #type_path::deserialize(&element.elements)? });
} else {
deserialized_fields.push(quote! { #field_name: #type_path::deserialize(element.text.as_str())? });
Expand Down Expand Up @@ -609,11 +605,7 @@ fn serialize_element_named_struct(
_ => {
if field_name == "attributes" {
serialized_fields.push(quote! { attributes: #type_path::serialize(&element.attributes) });
} else if field
.attrs
.iter()
.any(|attr| attr.path().is_ident("flatten"))
{
} else if field.attrs.iter().any(|attr| attr.path().is_ident("flatten")) {
serialized_fields.push(quote! { elements: #type_path::serialize(&element.content) });
} else {
serialized_fields.push(quote! { text: #type_path::serialize(&element.content) });
Expand Down

0 comments on commit 93bcbb2

Please sign in to comment.