diff --git a/src/id3/v2/frame/mod.rs b/src/id3/v2/frame/mod.rs index 3241e65d..d1eba3e9 100644 --- a/src/id3/v2/frame/mod.rs +++ b/src/id3/v2/frame/mod.rs @@ -26,9 +26,7 @@ use std::hash::{Hash, Hasher}; /// are supposed to have an empty content descriptor. Only those /// are currently supported as [`TagItem`]s to avoid ambiguities /// and to prevent inconsistencies when writing them. -pub(super) const fn empty_content_descriptor() -> String { - String::new() -} +pub(super) const EMPTY_CONTENT_DESCRIPTOR: String = String::new(); /// Unknown language-aware text frame /// @@ -295,7 +293,7 @@ impl From for Option> { FrameValue::Comment(LanguageFrame { encoding: TextEncoding::UTF8, language: UNKNOWN_LANGUAGE, - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: text, }) }, @@ -303,7 +301,7 @@ impl From for Option> { FrameValue::UnSyncText(LanguageFrame { encoding: TextEncoding::UTF8, language: UNKNOWN_LANGUAGE, - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: text, }) }, @@ -312,14 +310,14 @@ impl From for Option> { { FrameValue::UserURL(EncodedTextFrame { encoding: TextEncoding::UTF8, - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: text, }) }, (FrameID::Valid(ref s), ItemValue::Text(text)) if s == "TXXX" => { FrameValue::UserText(EncodedTextFrame { encoding: TextEncoding::UTF8, - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: text, }) }, @@ -403,25 +401,25 @@ impl<'a> TryFrom<&'a TagItem> for FrameRef<'a> { ("COMM", ItemValue::Text(text)) => FrameValue::Comment(LanguageFrame { encoding: TextEncoding::UTF8, language: UNKNOWN_LANGUAGE, - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: text.clone(), }), ("USLT", ItemValue::Text(text)) => FrameValue::UnSyncText(LanguageFrame { encoding: TextEncoding::UTF8, language: UNKNOWN_LANGUAGE, - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: text.clone(), }), ("WXXX", ItemValue::Locator(text) | ItemValue::Text(text)) => { FrameValue::UserURL(EncodedTextFrame { encoding: TextEncoding::UTF8, - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: text.clone(), }) }, ("TXXX", ItemValue::Text(text)) => FrameValue::UserText(EncodedTextFrame { encoding: TextEncoding::UTF8, - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: text.clone(), }), ("POPM", ItemValue::Binary(contents)) => { diff --git a/src/id3/v2/tag.rs b/src/id3/v2/tag.rs index bd6816cc..d3c32d8e 100644 --- a/src/id3/v2/tag.rs +++ b/src/id3/v2/tag.rs @@ -1,6 +1,6 @@ use super::flags::ID3v2TagFlags; use super::frame::id::FrameID; -use super::frame::{empty_content_descriptor, Frame, FrameFlags, FrameValue, UNKNOWN_LANGUAGE}; +use super::frame::{Frame, FrameFlags, FrameValue, EMPTY_CONTENT_DESCRIPTOR, UNKNOWN_LANGUAGE}; use super::ID3v2Version; use crate::error::{LoftyError, Result}; use crate::id3::v2::frame::FrameRef; @@ -283,7 +283,7 @@ impl ID3v2Tag { /// Returns all `COMM` frames with an empty content descriptor pub fn comments(&self) -> impl Iterator { self.frames.iter().filter_map(|frame| { - filter_comment_frame_by_description(frame, &empty_content_descriptor()) + filter_comment_frame_by_description(frame, &EMPTY_CONTENT_DESCRIPTOR) }) } @@ -434,9 +434,7 @@ impl Accessor for ID3v2Tag { fn comment(&self) -> Option> { self.frames .iter() - .find_map(|frame| { - filter_comment_frame_by_description(frame, &empty_content_descriptor()) - }) + .find_map(|frame| filter_comment_frame_by_description(frame, &EMPTY_CONTENT_DESCRIPTOR)) .map(|LanguageFrame { content, .. }| Cow::Borrowed(content.as_str())) } @@ -446,7 +444,7 @@ impl Accessor for ID3v2Tag { .frames .iter_mut() .find_map(|frame| { - filter_comment_frame_by_description_mut(frame, &empty_content_descriptor()) + filter_comment_frame_by_description_mut(frame, &EMPTY_CONTENT_DESCRIPTOR) }) .map(|LanguageFrame { content, .. }| content) { @@ -459,7 +457,7 @@ impl Accessor for ID3v2Tag { value: FrameValue::Comment(LanguageFrame { encoding: TextEncoding::UTF8, language: UNKNOWN_LANGUAGE, - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: value, }), flags: FrameFlags::default(), @@ -468,7 +466,7 @@ impl Accessor for ID3v2Tag { fn remove_comment(&mut self) { self.frames.retain(|frame| { - filter_comment_frame_by_description(frame, &empty_content_descriptor()).is_none() + filter_comment_frame_by_description(frame, &EMPTY_CONTENT_DESCRIPTOR).is_none() }) } } @@ -644,7 +642,7 @@ impl From for Tag { description, .. }) => { - if description == empty_content_descriptor() { + if description == EMPTY_CONTENT_DESCRIPTOR { for c in content.split(V4_MULTI_VALUE_SEPARATOR) { tag.items.push(TagItem::new( item_key.clone(), @@ -806,7 +804,7 @@ mod tests { Accessor, ItemKey, ItemValue, MimeType, Picture, PictureType, Tag, TagExt, TagItem, TagType, }; - use super::{empty_content_descriptor, COMMENT_FRAME_ID}; + use super::{COMMENT_FRAME_ID, EMPTY_CONTENT_DESCRIPTOR}; fn read_tag(path: &str) -> ID3v2Tag { let tag_bytes = crate::tag::utils::test_utils::read_path(path); @@ -866,7 +864,7 @@ mod tests { FrameValue::Comment(LanguageFrame { encoding, language: *b"eng", - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: String::from("Qux comment"), }), flags, @@ -1043,7 +1041,7 @@ mod tests { &FrameValue::Comment(LanguageFrame { encoding: TextEncoding::Latin1, language: *b"eng", - description: empty_content_descriptor(), + description: EMPTY_CONTENT_DESCRIPTOR, content: String::from("Qux comment") }) );