Skip to content

Commit

Permalink
Clippy suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Oct 2, 2024
1 parent 12703e5 commit e7a4c85
Show file tree
Hide file tree
Showing 59 changed files with 128 additions and 152 deletions.
2 changes: 1 addition & 1 deletion musicxml/examples/read_convert_score1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use musicxml::*;
fn main() {
// Read a MusicXML file of one score type as a different score type
let score = read_score_timewise("./musicxml/tests/Grande Valse Brillante.musicxml");
println! {"{:?}", score};
println! {"{score:?}"};
}
2 changes: 1 addition & 1 deletion musicxml/examples/read_convert_score2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use musicxml::*;
fn main() {
// Read a MusicXML file of one score type as a different score type
let score = read_score_partwise("./musicxml/tests/Grande Valse Brillante - Timewise.musicxml");
println! {"{:?}", score};
println! {"{score:?}"};
}
2 changes: 1 addition & 1 deletion musicxml/examples/read_musicxml_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use musicxml::*;
fn main() {
// Read and parse a MusicXML file
let score = read_score_partwise("./musicxml/tests/Grande Valse Brillante.musicxml");
println! {"{:?}", score};
println! {"{score:?}"};
}
2 changes: 1 addition & 1 deletion musicxml/examples/read_mxl_score.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ use musicxml::*;
fn main() {
// Read and parse a compressed MusicXML file
let score = read_score_partwise("./musicxml/tests/Grande Valse Brillante.mxl");
println! {"{:?}", score};
println! {"{score:?}"};
}
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/accordion_middle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl DatatypeDeserializer for AccordionMiddle {
1..=3 => Ok(AccordionMiddle(val)),
_ => Err(format!("Value {val} is invalid for the <accordion-middle> data type")),
},
Err(_) => Err(format!("Invalid value {} for <accordion-middle>", value)),
Err(_) => Err(format!("Invalid value {value} for <accordion-middle>")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/beam_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl DatatypeDeserializer for BeamLevel {
1..=8 => Ok(BeamLevel(val)),
_ => Err(format!("Value {val} is invalid for the <beam-level> data type")),
},
Err(_) => Err(format!("Invalid value {} for <beam-level>", value)),
Err(_) => Err(format!("Invalid value {value} for <beam-level>")),
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion musicxml/src/datatypes/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub struct Color {

impl Color {
/// Creates a new [Color] with the given red, green, blue, and alpha values.
#[must_use]
pub fn new(r: u8, g: u8, b: u8, a: u8) -> Self {
Color { r, g, b, a }
}
Expand Down Expand Up @@ -69,7 +70,7 @@ impl DatatypeDeserializer for Color {
))
}
} else {
Err(format!("Value {} is invalid for the <color> data type", value))
Err(format!("Value {value} is invalid for the <color> data type"))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/comma_separated_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl DatatypeDeserializer for CommaSeparatedText {
let mut text: Vec<String> = Vec::new();
value.split(',').for_each(|item| {
let res = item.trim();
if res.len() > 0 {
if !res.is_empty() {
text.push(res.to_string());
}
});
Expand Down
5 changes: 3 additions & 2 deletions musicxml/src/datatypes/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Date {

impl Date {
/// Creates a new [Date] with the given year, month, day, and timezone offset.
#[must_use]
pub fn new(year: u16, month: u8, date: u8, timezone_hours: i8, timezone_minutes: u8) -> Self {
Date {
year,
Expand Down Expand Up @@ -80,10 +81,10 @@ impl DatatypeDeserializer for Date {
{
Ok(date)
} else {
Err(format!("Value {} is invalid for the <date> data type", value))
Err(format!("Value {value} is invalid for the <date> data type"))
}
} else {
Err(format!("Value {} is invalid for the <date> data type", value))
Err(format!("Value {value} is invalid for the <date> data type"))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ mod decimal_tests {
fn deserialize_valid3() {
let result = Decimal::deserialize("3.234234");
assert!(result.is_ok());
assert_eq!(result.unwrap(), Decimal(3.234234));
assert_eq!(result.unwrap(), Decimal(3.234_234));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/divisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ mod divisions_tests {
fn deserialize_valid4() {
let result = Divisions::deserialize("223234");
assert!(result.is_ok());
assert_eq!(result.unwrap(), Divisions(223234));
assert_eq!(result.unwrap(), Divisions(223_234));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/ending_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl DatatypeDeserializer for EndingNumber {
} else if integer_regex.is_match(value) {
Ok(EndingNumber(value.split(' ').collect::<Vec<_>>().join("")))
} else {
Err(format!("Value {} is invalid for the <ending-number> data type", value))
Err(format!("Value {value} is invalid for the <ending-number> data type"))
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions musicxml/src/datatypes/fifths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ impl DatatypeDeserializer for Fifths {
match value.parse::<i8>() {
Ok(val) => match val {
-7..=7 => Ok(Fifths(val)),
_ => Err(format!("Value {} is invalid for the <fifths> data type", value)),
_ => Err(format!("Value {value} is invalid for the <fifths> data type")),
},
_ => Err(format!("Value {} is invalid for the <fifths> data type", value)),
_ => Err(format!("Value {value} is invalid for the <fifths> data type")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/font_family.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl DatatypeDeserializer for FontFamily {
let mut res: Vec<String> = Vec::new();
value.split(',').for_each(|item| {
let val = item.trim();
if val.len() > 0 {
if !val.is_empty() {
res.push(val.to_string());
}
});
Expand Down
6 changes: 3 additions & 3 deletions musicxml/src/datatypes/font_size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ impl DatatypeDeserializer for FontSize {
if dec_val > 0.0 {
Ok(FontSize::Decimal(dec_val))
} else {
Err(format!("Value {} is invalid for the <font-size> data type", value))
Err(format!("Value {value} is invalid for the <font-size> data type"))
}
} else if let Ok(font_size) = CssFontSize::deserialize(value) {
Ok(FontSize::Css(font_size))
} else {
Err(format!("Value {} is invalid for the <font-size> data type", value))
Err(format!("Value {value} is invalid for the <font-size> data type"))
}
}
}
Expand All @@ -54,7 +54,7 @@ mod font_size_tests {
fn deserialize_valid2() {
let result = FontSize::deserialize("3");
assert!(result.is_ok());
assert_eq!(result.unwrap(), FontSize::Decimal(3.0))
assert_eq!(result.unwrap(), FontSize::Decimal(3.0));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod integer_tests {
fn deserialize_valid2() {
let result = Integer::deserialize("-234234");
assert!(result.is_ok());
assert_eq!(result.unwrap(), Integer(-234234));
assert_eq!(result.unwrap(), Integer(-234_234));
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions musicxml/src/datatypes/measure_text.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ impl Deref for MeasureText {

impl DatatypeDeserializer for MeasureText {
fn deserialize(value: &str) -> Result<Self, String> {
if value.len() > 0 {
if !value.is_empty() {
Ok(MeasureText(String::from(value)))
} else {
Err(format!("Value {} is invalid for the <measure-text> data type", value))
Err(format!("Value {value} is invalid for the <measure-text> data type"))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/midi_128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl DatatypeDeserializer for Midi128 {
1..=128 => Ok(Midi128(val)),
_ => Err(format!("Value {val} is invalid for the <midi-128> data type")),
},
Err(_) => Err(format!("Invalid value {} for <midi-128>", value)),
Err(_) => Err(format!("Invalid value {value} for <midi-128>")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/midi_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl DatatypeDeserializer for Midi16 {
1..=16 => Ok(Midi16(val)),
_ => Err(format!("Value {val} is invalid for the <midi-16> data type")),
},
Err(_) => Err(format!("Invalid value {} for <midi-16>", value)),
Err(_) => Err(format!("Invalid value {value} for <midi-16>")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/midi_16384.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ impl DatatypeDeserializer for Midi16384 {
1..=16384 => Ok(Midi16384(val)),
_ => Err(format!("Value {val} is invalid for the <midi-16384> data type")),
},
Err(_) => Err(format!("Invalid value {} for <midi-16384>", value)),
Err(_) => Err(format!("Invalid value {value} for <midi-16384>")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/non_negative_decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl DatatypeDeserializer for NonNegativeDecimal {
x if x >= 0.0 => Ok(NonNegativeDecimal(val)),
_ => Err(format!("Value {val} is invalid for the NonNegativeDecimal data type")),
},
Err(_) => Err(format!("Invalid value {} for NonNegativeDecimal", value)),
Err(_) => Err(format!("Invalid value {value} for NonNegativeDecimal")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/non_negative_integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod non_negative_integer_tests {
fn deserialize_valid2() {
let result = NonNegativeInteger::deserialize("234566");
assert!(result.is_ok());
assert_eq!(result.unwrap(), NonNegativeInteger(234566));
assert_eq!(result.unwrap(), NonNegativeInteger(234_566));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/number_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl DatatypeDeserializer for NumberLevel {
if err.to_string().to_lowercase().contains("eof") {
Ok(NumberLevel(1))
} else {
Err(format!("Value {} is invalid for the <number-level> data type", value))
Err(format!("Value {value} is invalid for the <number-level> data type"))
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/number_of_lines.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl DatatypeDeserializer for NumberOfLines {
0..=3 => Ok(NumberOfLines(val)),
_ => Err(format!("Value {val} is invalid for the <number-of-lines> data type")),
},
Err(_) => Err(format!("Invalid value {} for <number-of-lines>", value)),
Err(_) => Err(format!("Invalid value {value} for <number-of-lines>")),
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions musicxml/src/datatypes/number_or_normal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ impl DatatypeDeserializer for NumberOrNormal {
Ok(NumberOrNormal::Normal)
} else {
Err(format!(
"Value {} is invalid for the <number-or-normal> data type",
value
"Value {value} is invalid for the <number-or-normal> data type"
))
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/numeral_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl DatatypeDeserializer for NumeralValue {
1..=7 => Ok(NumeralValue(val)),
_ => Err(format!("Value {val} is invalid for the <numeral-value> data type")),
},
Err(_) => Err(format!("Invalid value {} for <numeral-value>", value)),
Err(_) => Err(format!("Invalid value {value} for <numeral-value>")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/octave.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl DatatypeDeserializer for Octave {
0..=9 => Ok(Octave(val)),
_ => Err(format!("Value {val} is invalid for the <octave> data type")),
},
Err(_) => Err(format!("Invalid value {} for <octave>", value)),
Err(_) => Err(format!("Invalid value {value} for <octave>")),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions musicxml/src/datatypes/percent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ impl DatatypeDeserializer for Percent {
fn deserialize(value: &str) -> Result<Self, String> {
match value.parse::<f64>() {
Ok(val) => match val {
x if x >= 0.0 && x <= 100.0 => Ok(Percent(val)),
x if (0.0..=100.0).contains(&x) => Ok(Percent(val)),
_ => Err(format!("Value {val} is invalid for the <percent> data type")),
},
Err(_) => Err(format!("Invalid value {} for <percent>", value)),
Err(_) => Err(format!("Invalid value {value} for <percent>")),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion musicxml/src/datatypes/positive_divisions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl DatatypeDeserializer for PositiveDivisions {
1.. => Ok(PositiveDivisions(val)),
_ => Err(format!("Value {val} is invalid for the <positive-divisions> data type")),
},
Err(_) => Err(format!("Invalid value {} for <positive-divisions>", value)),
Err(_) => Err(format!("Invalid value {value} for <positive-divisions>")),
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions musicxml/src/datatypes/positive_integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl DatatypeDeserializer for PositiveInteger {
1.. => Ok(PositiveInteger(val)),
_ => Err(format!("Value {val} is invalid for the <positive-integer> data type")),
},
Err(_) => Err(format!("Invalid value {} for <positive-integer>", value)),
Err(_) => Err(format!("Invalid value {value} for <positive-integer>")),
}
}
}
Expand All @@ -43,7 +43,7 @@ mod positive_integer_tests {
fn deserialize_valid2() {
let result = PositiveInteger::deserialize("2345534234");
assert!(result.is_ok());
assert_eq!(result.unwrap(), PositiveInteger(2345534234));
assert_eq!(result.unwrap(), PositiveInteger(2_345_534_234));
}

#[test]
Expand Down
3 changes: 1 addition & 2 deletions musicxml/src/datatypes/positive_integer_or_empty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ impl DatatypeDeserializer for PositiveIntegerOrEmpty {
)),
},
Err(_) => Err(format!(
"Value {} is invalid for the <positive-integer-or-empty> data type",
value
"Value {value} is invalid for the <positive-integer-or-empty> data type"
)),
}
}
Expand Down
4 changes: 2 additions & 2 deletions musicxml/src/datatypes/rotation_degrees.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ impl DatatypeDeserializer for RotationDegrees {
fn deserialize(value: &str) -> Result<Self, String> {
match value.parse::<f32>() {
Ok(val) => match val {
x if x >= -180.0 && x <= 180.0 => Ok(RotationDegrees(val)),
x if (-180.0..=180.0).contains(&x) => Ok(RotationDegrees(val)),
_ => Err(format!("Value {val} is invalid for the <rotation-degrees> data type")),
},
Err(_) => Err(format!("Invalid value {} for <rotation-degrees>", value)),
Err(_) => Err(format!("Invalid value {value} for <rotation-degrees>")),
}
}
}
Expand Down
6 changes: 2 additions & 4 deletions musicxml/src/datatypes/smufl_accidental_glyph_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ impl DatatypeDeserializer for SmuflAccidentalGlyphName {
Ok(SmuflAccidentalGlyphName((*token).clone()))
} else {
Err(format!(
"Value {} is invalid for the <smufl-accidental-glyph-name> data type",
value
"Value {value} is invalid for the <smufl-accidental-glyph-name> data type"
))
}
} else {
Err(format!(
"Value {} is invalid for the <smufl-accidental-glyph-name> data type",
value
"Value {value} is invalid for the <smufl-accidental-glyph-name> data type"
))
}
}
Expand Down
6 changes: 2 additions & 4 deletions musicxml/src/datatypes/smufl_coda_glyph_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ impl DatatypeDeserializer for SmuflCodaGlyphName {
Ok(SmuflCodaGlyphName((*token).clone()))
} else {
Err(format!(
"Value {} is invalid for the <smufl-coda-glyph-name> data type",
value
"Value {value} is invalid for the <smufl-coda-glyph-name> data type"
))
}
} else {
Err(format!(
"Value {} is invalid for the <smufl-coda-glyph-name> data type",
value
"Value {value} is invalid for the <smufl-coda-glyph-name> data type"
))
}
}
Expand Down
6 changes: 2 additions & 4 deletions musicxml/src/datatypes/smufl_lyrics_glyph_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,12 @@ impl DatatypeDeserializer for SmuflLyricsGlyphName {
Ok(SmuflLyricsGlyphName((*token).clone()))
} else {
Err(format!(
"Value {} is invalid for the <smufl-lyrics-glyph-name> data type",
value
"Value {value} is invalid for the <smufl-lyrics-glyph-name> data type"
))
}
} else {
Err(format!(
"Value {} is invalid for the <smufl-lyrics-glyph-name> data type",
value
"Value {value} is invalid for the <smufl-lyrics-glyph-name> data type"
))
}
}
Expand Down
Loading

0 comments on commit e7a4c85

Please sign in to comment.