Fix all clippy errors

This commit is contained in:
Serial 2021-04-22 22:57:47 -04:00
parent 4713f4767c
commit c182b293fb
7 changed files with 50 additions and 57 deletions

View file

@ -4,7 +4,7 @@ use lofty::Tag;
macro_rules! test_read {
($function:ident, $path:expr) => {
fn $function() {
let _ = Tag::new().read_from_path($path).unwrap();
Tag::new().read_from_path($path).unwrap();
}
};
}
@ -18,13 +18,13 @@ test_read!(read_opus, "tests/assets/a.opus");
test_read!(read_wav, "tests/assets/a-id3.wav");
fn bench_ext(c: &mut Criterion) {
c.bench_function("APE - Extension", |b| b.iter(|| read_ape()));
c.bench_function("FLAC - Extension", |b| b.iter(|| read_flac()));
c.bench_function("MP4 - Extension", |b| b.iter(|| read_m4a()));
c.bench_function("MP3 - Extension", |b| b.iter(|| read_mp3()));
c.bench_function("OGG - Extension", |b| b.iter(|| read_ogg()));
c.bench_function("OPUS - Extension", |b| b.iter(|| read_opus()));
c.bench_function("WAV - Extension", |b| b.iter(|| read_wav()));
c.bench_function("APE - Extension", |b| b.iter(read_ape));
c.bench_function("FLAC - Extension", |b| b.iter(read_flac));
c.bench_function("MP4 - Extension", |b| b.iter(read_m4a));
c.bench_function("MP3 - Extension", |b| b.iter(read_mp3));
c.bench_function("OGG - Extension", |b| b.iter(read_ogg));
c.bench_function("OPUS - Extension", |b| b.iter(read_opus));
c.bench_function("WAV - Extension", |b| b.iter(read_wav));
}
criterion_group!(benches, bench_ext);

View file

@ -4,7 +4,7 @@ use lofty::Tag;
macro_rules! test_read {
($function:ident, $path:expr) => {
fn $function() {
let _ = Tag::new().read_from_path_signature($path).unwrap();
Tag::new().read_from_path_signature($path).unwrap();
}
};
}
@ -18,13 +18,13 @@ test_read!(read_opus, "tests/assets/a.opus");
test_read!(read_wav, "tests/assets/a.wav");
fn bench_sig(c: &mut Criterion) {
c.bench_function("APE - Signature", |b| b.iter(|| read_ape()));
c.bench_function("FLAC - Signature", |b| b.iter(|| read_flac()));
c.bench_function("MP4 - Signature", |b| b.iter(|| read_m4a()));
c.bench_function("MP3 - Signature", |b| b.iter(|| read_mp3()));
c.bench_function("OGG - Signature", |b| b.iter(|| read_ogg()));
c.bench_function("OPUS - Signature", |b| b.iter(|| read_opus()));
c.bench_function("WAV - Signature", |b| b.iter(|| read_wav()));
c.bench_function("APE - Signature", |b| b.iter(read_ape));
c.bench_function("FLAC - Signature", |b| b.iter(read_flac));
c.bench_function("MP4 - Signature", |b| b.iter(read_m4a));
c.bench_function("MP3 - Signature", |b| b.iter(read_mp3));
c.bench_function("OGG - Signature", |b| b.iter(read_ogg));
c.bench_function("OPUS - Signature", |b| b.iter(read_opus));
c.bench_function("WAV - Signature", |b| b.iter(read_wav));
}
criterion_group!(benches, bench_sig);

View file

@ -20,11 +20,11 @@ impl_tag!(Id3v2Tag, Id3v2InnerTag, TagType::Id3v2(Id3Format::Default));
impl Id3v2Tag {
#[allow(clippy::missing_errors_doc)]
pub fn read_from_path<P>(path: P, format: Id3Format) -> Result<Self>
pub fn read_from_path<P>(path: P, format: &Id3Format) -> Result<Self>
where
P: AsRef<Path>,
{
return match format {
match format {
Id3Format::Default => Ok(Self {
inner: Id3v2InnerTag::read_from_path(&path)?,
#[cfg(feature = "duration")]
@ -40,7 +40,7 @@ impl Id3v2Tag {
#[cfg(feature = "duration")]
duration: None, // TODO
}),
};
}
}
}
@ -192,7 +192,7 @@ impl AudioTagEdit for Id3v2Tag {
impl AudioTagWrite for Id3v2Tag {
fn write_to(&self, file: &mut File) -> Result<()> {
let mut id = [0; 4];
file.read(&mut id)?;
file.read_exact(&mut id)?;
file.seek(SeekFrom::Start(0))?;
match &id {

View file

@ -93,13 +93,13 @@ impl Tag {
#[cfg(feature = "ape")]
TagType::Ape => Ok(Box::new(ApeTag::read_from_path(path)?)),
#[cfg(feature = "id3")]
TagType::Id3v2(underlying) => Ok(Box::new(Id3v2Tag::read_from_path(path, underlying)?)),
TagType::Id3v2(format) => Ok(Box::new(Id3v2Tag::read_from_path(path, &format)?)),
#[cfg(feature = "mp4")]
TagType::Mp4 => Ok(Box::new(Mp4Tag::read_from_path(path)?)),
#[cfg(feature = "riff")]
TagType::RiffInfo => Ok(Box::new(RiffTag::read_from_path(path)?)),
#[cfg(any(feature = "vorbis", feature = "flac", feature = "opus"))]
TagType::Vorbis(format) => Ok(Box::new(VorbisTag::read_from_path(path, format.clone())?)),
TagType::Vorbis(format) => Ok(Box::new(VorbisTag::read_from_path(path, format)?)),
}
}
}
@ -175,7 +175,7 @@ impl TagType {
}
}
fn try_from_sig(data: &[u8]) -> Result<Self> {
if data.len() < 1 {
if data.is_empty() {
return Err(Error::EmptyFile);
}
@ -192,27 +192,23 @@ impl TagType {
let mut data = Cursor::new(data);
let mut found_id3 = false;
loop {
if let (Ok(fourcc), Ok(size)) = (
data.read_u32::<LittleEndian>(),
data.read_u32::<BigEndian>(),
) {
if fourcc.to_le_bytes() == FORM {
data.seek(SeekFrom::Current(4))?;
continue;
}
while let (Ok(fourcc), Ok(size)) = (
data.read_u32::<LittleEndian>(),
data.read_u32::<BigEndian>(),
) {
if fourcc.to_le_bytes() == FORM {
data.seek(SeekFrom::Current(4))?;
continue;
}
if fourcc.to_le_bytes()[..3] == ID3 {
found_id3 = true;
break;
}
data.seek(SeekFrom::Current(
u32::from_be_bytes(size.to_be_bytes()) as i64
))?;
} else {
if fourcc.to_le_bytes()[..3] == ID3 {
found_id3 = true;
break;
}
data.seek(SeekFrom::Current(i64::from(u32::from_be_bytes(
size.to_be_bytes(),
))))?;
}
if found_id3 {
@ -247,20 +243,16 @@ impl TagType {
let mut found_id3 = false;
loop {
if let (Ok(fourcc), Ok(size)) = (
data.read_u32::<LittleEndian>(),
data.read_u32::<LittleEndian>(),
) {
if &fourcc.to_le_bytes() == b"ID3 " {
found_id3 = true;
break;
}
data.set_position(data.position() + size as u64)
} else {
while let (Ok(fourcc), Ok(size)) = (
data.read_u32::<LittleEndian>(),
data.read_u32::<LittleEndian>(),
) {
if &fourcc.to_le_bytes() == b"ID3 " {
found_id3 = true;
break;
}
data.set_position(data.position() + u64::from(size))
}
if found_id3 {

View file

@ -127,5 +127,6 @@ pub trait ToAnyTag: ToAny {
pub trait ToAny {
fn to_any(&self) -> &dyn std::any::Any;
#[allow(clippy::wrong_self_convention)]
fn to_any_mut(&mut self) -> &mut dyn std::any::Any;
}

View file

@ -36,9 +36,9 @@ fn test_inner() {
// Create timestamp and change date_recorded
let timestamp = id3::Timestamp {
year: 2013,
month: Some(2u8),
day: Some(5u8),
hour: Some(6u8),
month: Some(2_u8),
day: Some(5_u8),
hour: Some(6_u8),
minute: None,
second: None,
};

View file

@ -1,5 +1,5 @@
#![cfg(feature = "default")]
use lofty::{MimeType, Picture, Tag};
use lofty::Tag;
macro_rules! full_test {
($function:ident, $file:expr) => {