Skip to content

Commit

Permalink
Even more clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
hedgecrw committed Oct 2, 2024
1 parent e7a4c85 commit 5e94f82
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ checknostd:
cd ensure_no_std && cargo rustc -- -C link-arg=-nostartfiles

check:
cargo clippy -- -W clippy::all -W clippy::correctness -W clippy::suspicious -W clippy::complexity -W clippy::perf -W clippy::style -W clippy::pedantic -A clippy::missing_errors_doc -A clippy::missing_panics_doc -A clippy::doc_markdown -A clippy::wildcard_imports -D warnings
cargo clippy -- -W clippy::all -W clippy::correctness -W clippy::suspicious -W clippy::complexity -W clippy::perf -W clippy::style -W clippy::pedantic -A clippy::missing_errors_doc -A clippy::missing_panics_doc -A clippy::doc_markdown -A clippy::wildcard_imports -A clippy::module_name_repetitions -D warnings

testunit:
cargo test --features debug -- --nocapture
Expand Down
6 changes: 3 additions & 3 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.is_empty() {
Ok(MeasureText(String::from(value)))
} else {
if value.is_empty() {
Err(format!("Value {value} is invalid for the <measure-text> data type"))
} else {
Ok(MeasureText(String::from(value)))
}
}
}
Expand Down
1 change: 1 addition & 0 deletions musicxml/src/datatypes/staff_line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl DatatypeDeserializer for StaffLine {
fn deserialize(value: &str) -> Result<Self, String> {
match PositiveInteger::deserialize(value) {
Ok(val) => match *val {
#[allow(clippy::cast_possible_truncation)]
1..=255 => Ok(StaffLine(*val as u8)),
_ => Err(format!("Value {} is invalid for the <staff-line> data type", *val)),
},
Expand Down
1 change: 1 addition & 0 deletions musicxml/src/datatypes/staff_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl DatatypeDeserializer for StaffNumber {
fn deserialize(value: &str) -> Result<Self, String> {
match PositiveInteger::deserialize(value) {
Ok(val) => match *val {
#[allow(clippy::cast_possible_truncation)]
1..=255 => Ok(StaffNumber(*val as u8)),
_ => Err(format!("Value {} is invalid for the <staff-number> data type", *val)),
},
Expand Down
1 change: 1 addition & 0 deletions musicxml/src/datatypes/string_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ impl DatatypeDeserializer for StringNumber {
fn deserialize(value: &str) -> Result<Self, String> {
match PositiveInteger::deserialize(value) {
Ok(val) => match *val {
#[allow(clippy::cast_possible_truncation)]
1..=255 => Ok(StringNumber(*val as u8)),
_ => Err(format!("Value {} is invalid for the <string> data type", *val)),
},
Expand Down
1 change: 1 addition & 0 deletions musicxml/src/datatypes/time_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ impl DatatypeDeserializer for TimeOnly {
value.split(',').for_each(|item| {
if let Ok(token) = PositiveInteger::deserialize(item) {
match *token {
#[allow(clippy::cast_possible_truncation)]
1..=255 => res.push(*token as u8),
_ => errs = true,
}
Expand Down
1 change: 1 addition & 0 deletions musicxml/src/datatypes/yes_no_number.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ impl DatatypeSerializer for YesNoNumber {
impl DatatypeDeserializer for YesNoNumber {
fn deserialize(value: &str) -> Result<Self, String> {
if let Ok(dec_val) = Decimal::deserialize(value) {
#[allow(clippy::cast_possible_truncation)]
Ok(YesNoNumber::Decimal(*dec_val as f32))
} else if value.to_lowercase() == "yes" {
Ok(YesNoNumber::Yes)
Expand Down
6 changes: 3 additions & 3 deletions musicxml/src/datatypes/yyyy_mm_dd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ impl DatatypeDeserializer for YyyyMmDd {
let regex = Regex::new(r"([0-9]{4})-([0-9]{2})-([0-9]{2})$").unwrap();
if let Some(captures) = regex.captures(value) {
let date = YyyyMmDd::new(
u16::from_str_radix(captures.get(1).unwrap().as_str(), 10).unwrap(),
u8::from_str_radix(captures.get(2).unwrap().as_str(), 10).unwrap(),
u8::from_str_radix(captures.get(3).unwrap().as_str(), 10).unwrap(),
captures.get(1).unwrap().as_str().parse::<u16>().unwrap(),
captures.get(2).unwrap().as_str().parse::<u8>().unwrap(),
captures.get(3).unwrap().as_str().parse::<u8>().unwrap(),
);
if date.month > 0 && date.month < 13 && date.date > 0 && date.date < 32 {
Ok(date)
Expand Down
8 changes: 4 additions & 4 deletions musicxml/src/elements/note.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl ContentDeserializer for GraceNormalInfo {
}
}
Ok(GraceNormalInfo {
chord: chord,
chord,
audible: if let Some(audible) = audible {
audible
} else {
Expand Down Expand Up @@ -177,7 +177,7 @@ impl ContentDeserializer for GraceCueInfo {
} else {
Err("Missing <cue> element")?
},
chord: chord,
chord,
audible: if let Some(audible) = audible {
audible
} else {
Expand Down Expand Up @@ -282,7 +282,7 @@ impl ContentDeserializer for CueInfo {
} else {
Err("Missing <cue> element")?
},
chord: chord,
chord,
audible: if let Some(audible) = audible {
audible
} else {
Expand Down Expand Up @@ -345,7 +345,7 @@ impl ContentDeserializer for NormalInfo {
}
}
Ok(NormalInfo {
chord: chord,
chord,
audible: if let Some(audible) = audible {
audible
} else {
Expand Down
6 changes: 3 additions & 3 deletions musicxml/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,8 @@ fn get_musicxml_contents_from_file(path: &str) -> Result<String, String> {
let file = archive
.get_file(full_path.as_str())
.ok_or("MXL file missing expected contents")?;
contents = core::str::from_utf8(file.data.as_slice())
.map_err(|e| e.to_string())?
.to_owned();
core::str::from_utf8(file.data.as_slice())
.map_err(|e| e.to_string())?.clone_into(&mut contents);
} else {
Err(String::from("Cannot find MusicXML file in compressed archive"))?;
}
Expand Down Expand Up @@ -111,6 +110,7 @@ fn write_musicxml_to_file(path: &str, xml: &XmlElement, compressed: bool, pretty
let mut file = std::fs::OpenOptions::new()
.write(true)
.create(true)
.truncate(true)
.open(path)
.map_err(|e| e.to_string())?;
write_musicxml_file(&mut file, xml, pretty_print)
Expand Down
3 changes: 1 addition & 2 deletions musicxml/src/parser/xml_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ fn read_tag_str(str: &mut core::str::Chars) -> TagType {
TagType::Opening(tag)
};
}
'\r' => (),
'\n' => (),
'\r' | '\n' => (),
'/' => {
if in_string {
value.push(c);
Expand Down
8 changes: 4 additions & 4 deletions musicxml/src/parser/zip_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use alloc::{collections::BTreeMap, vec::Vec};
use core2::io::Read;
use libflate::deflate::{Decoder, Encoder};
use libflate::deflate::Decoder;

const DEFLATE_METHOD: u16 = 8;
const LOCAL_FILE_HEADER_LEN: usize = core::mem::size_of::<LocalFileHeader>();
Expand Down Expand Up @@ -232,14 +232,14 @@ impl<'a> Iterator for ZipParser<'a> {
self.buffer_len -= entry_length;

// Decompress the file if its method is DEFLATE
if compression_method != DEFLATE_METHOD {
self.next()
} else {
if compression_method == DEFLATE_METHOD {
Some(LocalFile::new(
file_name,
file_header,
LocalFileHeader::from_bytes(file_header),
))
} else {
self.next()
}
}
}
Expand Down

0 comments on commit 5e94f82

Please sign in to comment.