TaggedFile: Stop taking references to TagType

This commit is contained in:
Serial 2022-07-24 16:12:14 -04:00
parent f48014fda8
commit 790e175b30
No known key found for this signature in database
GPG key ID: DA95198DC17C4568
5 changed files with 18 additions and 17 deletions

View file

@ -15,6 +15,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- With the new `lofty_attr` crate, file creation has been simplified significantly.
It is available for both internal and external usage.
### Changed
- **TaggedFile**: `tag{_mut}` no longer takes a reference to `TagType`
## [0.7.3] - 2022-07-22
### Added

View file

@ -134,7 +134,6 @@ impl TaggedFile {
self.ty.supports_tag_type(tag_type)
}
// TODO: stop making these two take references to TagType
/// Get a reference to a specific [`TagType`]
///
/// # Examples
@ -148,14 +147,14 @@ impl TaggedFile {
/// let mut tagged_file = lofty::read_from_path(path_to_mp3, true)?;
///
/// // An ID3v2 tag
/// let tag = tagged_file.tag(&TagType::ID3v2);
/// let tag = tagged_file.tag(TagType::ID3v2);
///
/// assert!(tag.is_some());
/// assert_eq!(tag.unwrap().tag_type(), TagType::ID3v2);
/// # Ok(()) }
/// ```
pub fn tag(&self, tag_type: &TagType) -> Option<&Tag> {
self.tags.iter().find(|i| i.tag_type() == *tag_type)
pub fn tag(&self, tag_type: TagType) -> Option<&Tag> {
self.tags.iter().find(|i| i.tag_type() == tag_type)
}
/// Get a mutable reference to a specific [`TagType`]
@ -171,7 +170,7 @@ impl TaggedFile {
/// let mut tagged_file = lofty::read_from_path(path_to_mp3, true)?;
///
/// // An ID3v2 tag
/// let tag = tagged_file.tag(&TagType::ID3v2);
/// let tag = tagged_file.tag(TagType::ID3v2);
///
/// assert!(tag.is_some());
/// assert_eq!(tag.unwrap().tag_type(), TagType::ID3v2);
@ -179,8 +178,8 @@ impl TaggedFile {
/// // Alter the tag...
/// # Ok(()) }
/// ```
pub fn tag_mut(&mut self, tag_type: &TagType) -> Option<&mut Tag> {
self.tags.iter_mut().find(|i| i.tag_type() == *tag_type)
pub fn tag_mut(&mut self, tag_type: TagType) -> Option<&mut Tag> {
self.tags.iter_mut().find(|i| i.tag_type() == tag_type)
}
/// Returns the primary tag
@ -205,7 +204,7 @@ impl TaggedFile {
/// # Ok(()) }
/// ```
pub fn primary_tag(&self) -> Option<&Tag> {
self.tag(&self.primary_tag_type())
self.tag(self.primary_tag_type())
}
/// Gets a mutable reference to the file's "Primary tag"
@ -232,7 +231,7 @@ impl TaggedFile {
/// # Ok(()) }
/// ```
pub fn primary_tag_mut(&mut self) -> Option<&mut Tag> {
self.tag_mut(&self.primary_tag_type())
self.tag_mut(self.primary_tag_type())
}
/// Gets the first tag, if there are any

View file

@ -11,9 +11,9 @@ use crate::mp4::Mp4File;
use crate::ogg::opus::OpusFile;
use crate::ogg::speex::SpeexFile;
use crate::ogg::vorbis::VorbisFile;
use crate::resolve::CUSTOM_RESOLVERS;
use crate::wavpack::WavPackFile;
use crate::resolve::CUSTOM_RESOLVERS;
use std::fs::File;
use std::io::{BufReader, Cursor, Read, Seek, SeekFrom};
use std::path::Path;

View file

@ -108,8 +108,7 @@ fn remove(path: &str, tag_type: TagType) {
let tagged_file = lofty::read_from(&mut file, false).unwrap();
// Verify we have both the vendor and artist
assert!(
tagged_file.tag(&tag_type).is_some()
&& tagged_file.tag(&tag_type).unwrap().item_count() == 2
tagged_file.tag(tag_type).is_some() && tagged_file.tag(tag_type).unwrap().item_count() == 2
);
file.rewind().unwrap();
@ -119,7 +118,7 @@ fn remove(path: &str, tag_type: TagType) {
let tagged_file = lofty::read_from(&mut file, false).unwrap();
// We can't completely remove the tag since metadata packets are mandatory, but it should only have to vendor now
assert_eq!(tagged_file.tag(&tag_type).unwrap().item_count(), 1);
assert_eq!(tagged_file.tag(tag_type).unwrap().item_count(), 1);
}
#[test]

View file

@ -23,9 +23,9 @@ macro_rules! verify_artist {
verify_artist!($file, $method($arg), $expected_value, $item_count)
}};
($file:ident, $method:ident($($arg:path)?), $expected_value:literal, $item_count:expr) => {{
assert!($file.$method($(&$arg)?).is_some());
assert!($file.$method($($arg)?).is_some());
let tag = $file.$method($(&$arg)?).unwrap();
let tag = $file.$method($($arg)?).unwrap();
assert_eq!(tag.item_count(), $item_count);
@ -79,7 +79,7 @@ macro_rules! remove_tag {
let mut file = temp_file!($path);
let tagged_file = lofty::read_from(&mut file, false).unwrap();
assert!(tagged_file.tag(&$tag_type).is_some());
assert!(tagged_file.tag($tag_type).is_some());
file.seek(std::io::SeekFrom::Start(0)).unwrap();
@ -88,6 +88,6 @@ macro_rules! remove_tag {
file.seek(std::io::SeekFrom::Start(0)).unwrap();
let tagged_file = lofty::read_from(&mut file, false).unwrap();
assert!(tagged_file.tag(&$tag_type).is_none());
assert!(tagged_file.tag($tag_type).is_none());
};
}