From e01d875e055a7603ff0d217225f7402990fee1f0 Mon Sep 17 00:00:00 2001 From: Serial <69764315+Serial-ATA@users.noreply.github.com> Date: Sat, 19 Feb 2022 10:14:14 -0500 Subject: [PATCH] Remove unwraps; Stop taking references to `Copy` types --- examples/tag_stripper.rs | 2 +- src/ape/mod.rs | 2 +- src/id3/v2/util/text_utils.rs | 2 +- src/iff/aiff/mod.rs | 2 +- src/iff/aiff/read.rs | 50 ++++++++++++++++++++--------------- src/iff/aiff/tag.rs | 2 +- src/iff/wav/mod.rs | 2 +- src/iff/wav/read.rs | 4 ++- src/lib.rs | 8 +++--- src/mp3/mod.rs | 2 +- src/mp3/read.rs | 5 ++-- src/mp4/mod.rs | 4 +-- src/mp4/moov.rs | 12 ++++----- src/ogg/flac/mod.rs | 4 +-- src/ogg/flac/write.rs | 2 +- src/ogg/opus/mod.rs | 4 +-- src/ogg/speex/mod.rs | 4 +-- src/ogg/vorbis/mod.rs | 4 +-- src/types/file.rs | 32 +++++++++++----------- src/types/tag.rs | 6 ++--- tests/files/aiff.rs | 4 +-- tests/files/ape.rs | 4 +-- tests/files/mp4.rs | 4 +-- tests/files/mpeg.rs | 6 ++--- tests/files/ogg.rs | 26 +++++++----------- tests/files/wav.rs | 4 +-- 26 files changed, 102 insertions(+), 99 deletions(-) diff --git a/examples/tag_stripper.rs b/examples/tag_stripper.rs index 300870ec..7ffa3409 100644 --- a/examples/tag_stripper.rs +++ b/examples/tag_stripper.rs @@ -24,7 +24,7 @@ fn main() { let tag_type = tag.tag_type(); println!("{}: {:?}", num, tag_type); - available_tag_types.push(*tag_type); + available_tag_types.push(tag_type); } let mut to_remove = None; diff --git a/src/ape/mod.rs b/src/ape/mod.rs index 06313c4e..54a1bc8f 100644 --- a/src/ape/mod.rs +++ b/src/ape/mod.rs @@ -98,7 +98,7 @@ impl AudioFile for ApeFile { false } - fn contains_tag_type(&self, tag_type: &TagType) -> bool { + fn contains_tag_type(&self, tag_type: TagType) -> bool { match tag_type { #[cfg(feature = "ape")] TagType::Ape => self.ape_tag.is_some(), diff --git a/src/id3/v2/util/text_utils.rs b/src/id3/v2/util/text_utils.rs index 89a77306..6f92961c 100644 --- a/src/id3/v2/util/text_utils.rs +++ b/src/id3/v2/util/text_utils.rs @@ -137,7 +137,7 @@ pub(crate) fn utf16_decode(reader: &[u8], endianness: fn([u8; 2]) -> u16) -> Res .chunks_exact(2) .map_while(|c| match c { [0, 0] => None, - _ => Some(endianness(c.try_into().unwrap())), + _ => Some(endianness(c.try_into().unwrap())), // Infallible }) .collect(); diff --git a/src/iff/aiff/mod.rs b/src/iff/aiff/mod.rs index 8d2b488c..8a958cb6 100644 --- a/src/iff/aiff/mod.rs +++ b/src/iff/aiff/mod.rs @@ -73,7 +73,7 @@ impl AudioFile for AiffFile { false } - fn contains_tag_type(&self, tag_type: &TagType) -> bool { + fn contains_tag_type(&self, tag_type: TagType) -> bool { match tag_type { #[cfg(feature = "id3v2")] TagType::Id3v2 => self.id3v2_tag.is_some(), diff --git a/src/iff/aiff/read.rs b/src/iff/aiff/read.rs index a5fd66f5..8d5323b9 100644 --- a/src/iff/aiff/read.rs +++ b/src/iff/aiff/read.rs @@ -23,7 +23,9 @@ where return Err(LoftyError::new(ErrorKind::UnknownFormat)); } - Ok(u32::from_be_bytes(id[4..8].try_into().unwrap())) + Ok(u32::from_be_bytes( + id[4..8].try_into().unwrap(), // Infallible + )) } pub(crate) fn read_from(data: &mut R, read_properties: bool) -> Result @@ -120,30 +122,34 @@ where } } - let properties = if read_properties { - if comm.is_none() { - return Err(FileDecodingError::new( - FileType::AIFF, - "File does not contain a \"COMM\" chunk", - ) - .into()); - } + let properties; + if read_properties { + match comm { + Some(comm) => { + if stream_len == 0 { + return Err(FileDecodingError::new( + FileType::AIFF, + "File does not contain a \"SSND\" chunk", + ) + .into()); + } - if stream_len == 0 { - return Err(FileDecodingError::new( - FileType::AIFF, - "File does not contain a \"SSND\" chunk", - ) - .into()); + properties = super::properties::read_properties( + &mut &*comm, + stream_len, + data.seek(SeekFrom::Current(0))?, + )?; + }, + None => { + return Err(FileDecodingError::new( + FileType::AIFF, + "File does not contain a \"COMM\" chunk", + ) + .into()); + }, } - - super::properties::read_properties( - &mut &*comm.unwrap(), - stream_len, - data.seek(SeekFrom::Current(0))?, - )? } else { - FileProperties::default() + properties = FileProperties::default(); }; Ok(AiffFile { diff --git a/src/iff/aiff/tag.rs b/src/iff/aiff/tag.rs index 49ec8097..14bc31e6 100644 --- a/src/iff/aiff/tag.rs +++ b/src/iff/aiff/tag.rs @@ -383,7 +383,7 @@ where chunks_remove.sort_unstable(); chunks_remove.reverse(); - let first = chunks_remove.pop().unwrap(); + let first = chunks_remove.pop().unwrap(); // Infallible for (s, e) in &chunks_remove { file_bytes.drain(*s as usize..*e as usize); diff --git a/src/iff/wav/mod.rs b/src/iff/wav/mod.rs index 45bcb53b..2889b10c 100644 --- a/src/iff/wav/mod.rs +++ b/src/iff/wav/mod.rs @@ -77,7 +77,7 @@ impl AudioFile for WavFile { false } - fn contains_tag_type(&self, tag_type: &TagType) -> bool { + fn contains_tag_type(&self, tag_type: TagType) -> bool { match tag_type { #[cfg(feature = "id3v2")] TagType::Id3v2 => self.id3v2_tag.is_some(), diff --git a/src/iff/wav/read.rs b/src/iff/wav/read.rs index d394595a..0b780395 100644 --- a/src/iff/wav/read.rs +++ b/src/iff/wav/read.rs @@ -31,7 +31,9 @@ where ); } - Ok(u32::from_le_bytes(id[4..8].try_into().unwrap())) + Ok(u32::from_le_bytes( + id[4..8].try_into().unwrap(), // Infallible + )) } pub(crate) fn read_from(data: &mut R, read_properties: bool) -> Result diff --git a/src/lib.rs b/src/lib.rs index ae477bdd..0c75aef7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -76,11 +76,11 @@ //! let tagged_file = read_from_path("tests/files/assets/minimal/full_test.mp3", false)?; //! //! // Get the primary tag (ID3v2 in this case) -//! let id3v2 = tagged_file.primary_tag().unwrap(); +//! let id3v2 = tagged_file.primary_tag(); //! //! // If the primary tag doesn't exist, or the tag types //! // don't matter, the first tag can be retrieved -//! let unknown_first_tag = tagged_file.first_tag().unwrap(); +//! let unknown_first_tag = tagged_file.first_tag(); //! # Ok(()) //! # } //! ``` @@ -102,8 +102,8 @@ //! assert_eq!(mpeg_file.properties().channels(), 2); //! //! // Here we have a file with multiple tags -//! assert!(mpeg_file.contains_tag_type(&TagType::Id3v2)); -//! assert!(mpeg_file.contains_tag_type(&TagType::Ape)); +//! assert!(mpeg_file.contains_tag_type(TagType::Id3v2)); +//! assert!(mpeg_file.contains_tag_type(TagType::Ape)); //! # Ok(()) //! # } //! ``` diff --git a/src/mp3/mod.rs b/src/mp3/mod.rs index 21a9a4b3..b9923c8d 100644 --- a/src/mp3/mod.rs +++ b/src/mp3/mod.rs @@ -85,7 +85,7 @@ impl AudioFile for Mp3File { false } - fn contains_tag_type(&self, tag_type: &TagType) -> bool { + fn contains_tag_type(&self, tag_type: TagType) -> bool { match tag_type { #[cfg(feature = "ape")] TagType::Ape => self.ape_tag.is_some(), diff --git a/src/mp3/read.rs b/src/mp3/read.rs index d0fbad1b..8913c168 100644 --- a/src/mp3/read.rs +++ b/src/mp3/read.rs @@ -83,7 +83,7 @@ where }, // Tags might be followed by junk bytes before the first MP3 frame begins _ => { - // seek back the length of the temporary header buffer, to include them + // Seek back the length of the temporary header buffer, to include them // in the frame sync search #[allow(clippy::neg_multiply)] let start_of_search_area = reader.seek(SeekFrom::Current(-1 * header.len() as i64))?; @@ -102,7 +102,8 @@ where // We have found the first frame break; } - // the search for sync bits was unsuccessful + + // The search for sync bits was unsuccessful return Err(FileDecodingError::new( FileType::MP3, "File contains an invalid frame", diff --git a/src/mp4/mod.rs b/src/mp4/mod.rs index aa2c1789..d6e5b7a8 100644 --- a/src/mp4/mod.rs +++ b/src/mp4/mod.rs @@ -89,9 +89,9 @@ impl AudioFile for Mp4File { } #[allow(unreachable_code, unused_variables)] - fn contains_tag_type(&self, tag_type: &TagType) -> bool { + fn contains_tag_type(&self, tag_type: TagType) -> bool { #[cfg(feature = "mp4_ilst")] - return tag_type == &TagType::Mp4Ilst && self.ilst.is_some(); + return tag_type == TagType::Mp4Ilst && self.ilst.is_some(); false } diff --git a/src/mp4/moov.rs b/src/mp4/moov.rs index a23332c5..7eb3af5f 100644 --- a/src/mp4/moov.rs +++ b/src/mp4/moov.rs @@ -23,22 +23,22 @@ impl Moov { where R: Read + Seek, { - let mut moov = (false, None); + let mut moov = None; while let Ok(atom) = AtomInfo::read(data) { if atom.ident == AtomIdent::Fourcc(*b"moov") { - moov = (true, Some(atom)); + moov = Some(atom); break; } skip_unneeded(data, atom.extended, atom.len)?; } - if !moov.0 { - return Err(FileDecodingError::new(FileType::MP4, "No \"moov\" atom found").into()); + if let Some(moov) = moov { + Ok(moov) + } else { + Err(FileDecodingError::new(FileType::MP4, "No \"moov\" atom found").into()) } - - Ok(moov.1.unwrap()) } pub(crate) fn parse(data: &mut R, read_properties: bool) -> Result diff --git a/src/ogg/flac/mod.rs b/src/ogg/flac/mod.rs index c898964f..230ee64f 100644 --- a/src/ogg/flac/mod.rs +++ b/src/ogg/flac/mod.rs @@ -62,9 +62,9 @@ impl AudioFile for FlacFile { } #[allow(unused_variables)] - fn contains_tag_type(&self, tag_type: &TagType) -> bool { + fn contains_tag_type(&self, tag_type: TagType) -> bool { #[cfg(feature = "vorbis_comments")] - return tag_type == &TagType::VorbisComments && self.vorbis_comments.is_some(); + return tag_type == TagType::VorbisComments && self.vorbis_comments.is_some(); #[cfg(not(feature = "vorbis_comments"))] return false; diff --git a/src/ogg/flac/write.rs b/src/ogg/flac/write.rs index 116b374f..1b1a57b8 100644 --- a/src/ogg/flac/write.rs +++ b/src/ogg/flac/write.rs @@ -96,7 +96,7 @@ where blocks_remove.sort_unstable(); blocks_remove.reverse(); - let first = blocks_remove.pop().unwrap(); + let first = blocks_remove.pop().unwrap(); // Infallible for (s, e) in &blocks_remove { file_bytes.drain(*s as usize..*e as usize); diff --git a/src/ogg/opus/mod.rs b/src/ogg/opus/mod.rs index d5a92454..6fc6760b 100644 --- a/src/ogg/opus/mod.rs +++ b/src/ogg/opus/mod.rs @@ -61,8 +61,8 @@ impl AudioFile for OpusFile { true } - fn contains_tag_type(&self, tag_type: &TagType) -> bool { - tag_type == &TagType::VorbisComments + fn contains_tag_type(&self, tag_type: TagType) -> bool { + tag_type == TagType::VorbisComments } } diff --git a/src/ogg/speex/mod.rs b/src/ogg/speex/mod.rs index 0425afc2..4844e083 100644 --- a/src/ogg/speex/mod.rs +++ b/src/ogg/speex/mod.rs @@ -60,8 +60,8 @@ impl AudioFile for SpeexFile { true } - fn contains_tag_type(&self, tag_type: &TagType) -> bool { - tag_type == &TagType::VorbisComments + fn contains_tag_type(&self, tag_type: TagType) -> bool { + tag_type == TagType::VorbisComments } } diff --git a/src/ogg/vorbis/mod.rs b/src/ogg/vorbis/mod.rs index 9ad9eb6f..82f9a4ed 100644 --- a/src/ogg/vorbis/mod.rs +++ b/src/ogg/vorbis/mod.rs @@ -64,8 +64,8 @@ impl AudioFile for VorbisFile { true } - fn contains_tag_type(&self, tag_type: &TagType) -> bool { - tag_type == &TagType::VorbisComments + fn contains_tag_type(&self, tag_type: TagType) -> bool { + tag_type == TagType::VorbisComments } } diff --git a/src/types/file.rs b/src/types/file.rs index 93fe68ac..ed8fdda0 100644 --- a/src/types/file.rs +++ b/src/types/file.rs @@ -30,7 +30,7 @@ pub trait AudioFile: Into { /// Checks if the file contains any tags fn contains_tag(&self) -> bool; /// Checks if the file contains the given [`TagType`] - fn contains_tag_type(&self, tag_type: &TagType) -> bool; + fn contains_tag_type(&self, tag_type: TagType) -> bool; } /// A generic representation of a file @@ -47,8 +47,8 @@ pub struct TaggedFile { impl TaggedFile { /// Returns the file's [`FileType`] - pub fn file_type(&self) -> &FileType { - &self.ty + pub fn file_type(&self) -> FileType { + self.ty } /// Returns the file's [`FileProperties`] @@ -70,17 +70,17 @@ impl TaggedFile { /// Determines whether the file supports the given [`TagType`] pub fn supports_tag_type(&self, tag_type: TagType) -> bool { - self.ty.supports_tag_type(&tag_type) + self.ty.supports_tag_type(tag_type) } /// Get a reference to a specific [`TagType`] pub fn tag(&self, tag_type: &TagType) -> Option<&Tag> { - self.tags.iter().find(|i| i.tag_type() == tag_type) + self.tags.iter().find(|i| i.tag_type() == *tag_type) } /// Get a mutable reference to a specific [`TagType`] pub fn tag_mut(&mut self, tag_type: &TagType) -> Option<&mut Tag> { - self.tags.iter_mut().find(|i| i.tag_type() == tag_type) + self.tags.iter_mut().find(|i| i.tag_type() == *tag_type) } /// Returns the primary tag @@ -114,7 +114,7 @@ impl TaggedFile { /// /// If a tag is replaced, it will be returned pub fn insert_tag(&mut self, tag: Tag) -> Option { - let tag_type = *tag.tag_type(); + let tag_type = tag.tag_type(); if self.supports_tag_type(tag_type) { let ret = self.remove_tag(tag_type); @@ -132,7 +132,7 @@ impl TaggedFile { pub fn remove_tag(&mut self, tag_type: TagType) -> Option { self.tags .iter() - .position(|t| t.tag_type() == &tag_type) + .position(|t| t.tag_type() == tag_type) .map(|pos| self.tags.remove(pos)) } @@ -225,28 +225,28 @@ impl FileType { } /// Returns if the target `FileType` supports a [`TagType`] - pub fn supports_tag_type(&self, tag_type: &TagType) -> bool { + pub fn supports_tag_type(&self, tag_type: TagType) -> bool { match self { #[cfg(feature = "id3v2")] FileType::AIFF | FileType::APE | FileType::MP3 | FileType::WAV - if tag_type == &TagType::Id3v2 => + if tag_type == TagType::Id3v2 => { true }, #[cfg(feature = "aiff_text_chunks")] - FileType::AIFF if tag_type == &TagType::AiffText => true, + FileType::AIFF if tag_type == TagType::AiffText => true, #[cfg(feature = "id3v1")] - FileType::APE | FileType::MP3 if tag_type == &TagType::Id3v1 => true, + FileType::APE | FileType::MP3 if tag_type == TagType::Id3v1 => true, #[cfg(feature = "ape")] - FileType::APE | FileType::MP3 if tag_type == &TagType::Ape => true, + FileType::APE | FileType::MP3 if tag_type == TagType::Ape => true, #[cfg(feature = "vorbis_comments")] FileType::Opus | FileType::FLAC | FileType::Vorbis | FileType::Speex => { - tag_type == &TagType::VorbisComments + tag_type == TagType::VorbisComments }, #[cfg(feature = "mp4_ilst")] - FileType::MP4 => tag_type == &TagType::Mp4Ilst, + FileType::MP4 => tag_type == TagType::Mp4Ilst, #[cfg(feature = "riff_info_list")] - FileType::WAV => tag_type == &TagType::RiffInfo, + FileType::WAV => tag_type == TagType::RiffInfo, _ => false, } } diff --git a/src/types/tag.rs b/src/types/tag.rs index 99de4e55..5a8b4ae0 100644 --- a/src/types/tag.rs +++ b/src/types/tag.rs @@ -130,8 +130,8 @@ impl Tag { } /// Returns the [`TagType`] - pub fn tag_type(&self) -> &TagType { - &self.tag_type + pub fn tag_type(&self) -> TagType { + self.tag_type } /// Returns the number of [`TagItem`]s @@ -440,7 +440,7 @@ impl TagType { None => return Err(LoftyError::new(ErrorKind::UnknownFormat)), }; - if !file_type.supports_tag_type(self) { + if !file_type.supports_tag_type(*self) { return Err(LoftyError::new(ErrorKind::UnsupportedTag)); } diff --git a/tests/files/aiff.rs b/tests/files/aiff.rs index 6805b817..19927a58 100644 --- a/tests/files/aiff.rs +++ b/tests/files/aiff.rs @@ -7,7 +7,7 @@ fn read() { // Here we have an AIFF file with both an ID3v2 chunk and text chunks let file = lofty::read_from_path("tests/files/assets/minimal/full_test.aiff", false).unwrap(); - assert_eq!(file.file_type(), &FileType::AIFF); + assert_eq!(file.file_type(), FileType::AIFF); // Verify the ID3v2 tag first crate::verify_artist!(file, primary_tag, "Foo artist", 1); @@ -22,7 +22,7 @@ fn write() { let mut tagged_file = lofty::read_from(&mut file, false).unwrap(); - assert_eq!(tagged_file.file_type(), &FileType::AIFF); + assert_eq!(tagged_file.file_type(), FileType::AIFF); // ID3v2 crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist"); diff --git a/tests/files/ape.rs b/tests/files/ape.rs index 3bc26fd2..b0c6bb2c 100644 --- a/tests/files/ape.rs +++ b/tests/files/ape.rs @@ -7,7 +7,7 @@ fn read() { // Here we have an APE file with an ID3v2, ID3v1, and an APEv2 tag let file = lofty::read_from_path("tests/files/assets/minimal/full_test.ape", false).unwrap(); - assert_eq!(file.file_type(), &FileType::APE); + assert_eq!(file.file_type(), FileType::APE); // Verify the APEv2 tag first crate::verify_artist!(file, primary_tag, "Foo artist", 1); @@ -26,7 +26,7 @@ fn write() { let mut tagged_file = lofty::read_from(&mut file, false).unwrap(); - assert_eq!(tagged_file.file_type(), &FileType::APE); + assert_eq!(tagged_file.file_type(), FileType::APE); // APEv2 crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist"); diff --git a/tests/files/mp4.rs b/tests/files/mp4.rs index 56dfb45c..8dfc6fc7 100644 --- a/tests/files/mp4.rs +++ b/tests/files/mp4.rs @@ -8,7 +8,7 @@ fn read() { let file = lofty::read_from_path("tests/files/assets/minimal/m4a_codec_aac.m4a", false).unwrap(); - assert_eq!(file.file_type(), &FileType::MP4); + assert_eq!(file.file_type(), FileType::MP4); // Verify the ilst tag crate::verify_artist!(file, primary_tag, "Foo artist", 1); @@ -20,7 +20,7 @@ fn write() { let mut tagged_file = lofty::read_from(&mut file, false).unwrap(); - assert_eq!(tagged_file.file_type(), &FileType::MP4); + assert_eq!(tagged_file.file_type(), FileType::MP4); // ilst crate::set_artist!(tagged_file, tag_mut, TagType::Mp4Ilst, "Foo artist", 1 => file, "Bar artist"); diff --git a/tests/files/mpeg.rs b/tests/files/mpeg.rs index 21ab85fa..3155f088 100644 --- a/tests/files/mpeg.rs +++ b/tests/files/mpeg.rs @@ -7,7 +7,7 @@ fn read() { // Here we have an MP3 file with an ID3v2, ID3v1, and an APEv2 tag let file = lofty::read_from_path("tests/files/assets/minimal/full_test.mp3", false).unwrap(); - assert_eq!(file.file_type(), &FileType::MP3); + assert_eq!(file.file_type(), FileType::MP3); // Verify the ID3v2 tag first crate::verify_artist!(file, primary_tag, "Foo artist", 1); @@ -26,7 +26,7 @@ fn read_with_junk_bytes_between_frames() { lofty::read_from_path("tests/files/assets/junk_between_id3_and_mp3.mp3", true).unwrap(); // note that the file contains ID3v2 and ID3v1 data - assert_eq!(file.file_type(), &FileType::MP3); + assert_eq!(file.file_type(), FileType::MP3); let id3v2_tag = &file.tags()[0]; assert_eq!(id3v2_tag.artist(), Some("artist test")); @@ -49,7 +49,7 @@ fn write() { let mut tagged_file = lofty::read_from(&mut file, false).unwrap(); - assert_eq!(tagged_file.file_type(), &FileType::MP3); + assert_eq!(tagged_file.file_type(), FileType::MP3); // ID3v2 crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist"); diff --git a/tests/files/ogg.rs b/tests/files/ogg.rs index ee23faf7..d334e464 100644 --- a/tests/files/ogg.rs +++ b/tests/files/ogg.rs @@ -7,12 +7,12 @@ use std::io::{Seek, SeekFrom, Write}; #[test] fn opus_read() { - read("tests/files/assets/minimal/full_test.opus", &FileType::Opus) + read("tests/files/assets/minimal/full_test.opus", FileType::Opus) } #[test] fn opus_write() { - write("tests/files/assets/minimal/full_test.opus", &FileType::Opus) + write("tests/files/assets/minimal/full_test.opus", FileType::Opus) } #[test] @@ -26,12 +26,12 @@ fn opus_remove() { #[test] fn flac_read() { // FLAC does **not** require a Vorbis comment block be present, this file has one - read("tests/files/assets/minimal/full_test.flac", &FileType::FLAC) + read("tests/files/assets/minimal/full_test.flac", FileType::FLAC) } #[test] fn flac_write() { - write("tests/files/assets/minimal/full_test.flac", &FileType::FLAC) + write("tests/files/assets/minimal/full_test.flac", FileType::FLAC) } #[test] @@ -44,18 +44,12 @@ fn flac_remove() { #[test] fn vorbis_read() { - read( - "tests/files/assets/minimal/full_test.ogg", - &FileType::Vorbis, - ) + read("tests/files/assets/minimal/full_test.ogg", FileType::Vorbis) } #[test] fn vorbis_write() { - write( - "tests/files/assets/minimal/full_test.ogg", - &FileType::Vorbis, - ) + write("tests/files/assets/minimal/full_test.ogg", FileType::Vorbis) } #[test] @@ -68,12 +62,12 @@ fn vorbis_remove() { #[test] fn speex_read() { - read("tests/files/assets/minimal/full_test.spx", &FileType::Speex) + read("tests/files/assets/minimal/full_test.spx", FileType::Speex) } #[test] fn speex_write() { - write("tests/files/assets/minimal/full_test.spx", &FileType::Speex) + write("tests/files/assets/minimal/full_test.spx", FileType::Speex) } #[test] @@ -84,7 +78,7 @@ fn speex_remove() { ) } -fn read(path: &str, file_type: &FileType) { +fn read(path: &str, file_type: FileType) { let file = lofty::read_from_path(path, false).unwrap(); assert_eq!(file.file_type(), file_type); @@ -92,7 +86,7 @@ fn read(path: &str, file_type: &FileType) { crate::verify_artist!(file, primary_tag, "Foo artist", 2); } -fn write(path: &str, file_type: &FileType) { +fn write(path: &str, file_type: FileType) { let mut file = temp_file!(path); let mut tagged_file = lofty::read_from(&mut file, false).unwrap(); diff --git a/tests/files/wav.rs b/tests/files/wav.rs index cf223564..793a2a27 100644 --- a/tests/files/wav.rs +++ b/tests/files/wav.rs @@ -8,7 +8,7 @@ fn read() { let file = lofty::read_from_path("tests/files/assets/minimal/wav_format_pcm.wav", false).unwrap(); - assert_eq!(file.file_type(), &FileType::WAV); + assert_eq!(file.file_type(), FileType::WAV); // Verify the ID3v2 tag first crate::verify_artist!(file, primary_tag, "Foo artist", 1); @@ -23,7 +23,7 @@ fn write() { let mut tagged_file = lofty::read_from(&mut file, false).unwrap(); - assert_eq!(tagged_file.file_type(), &FileType::WAV); + assert_eq!(tagged_file.file_type(), FileType::WAV); // ID3v2 crate::set_artist!(tagged_file, primary_tag_mut, "Foo artist", 1 => file, "Bar artist");