id3v2: Change const fn into const

This commit is contained in:
Uwe Klotz 2023-01-15 10:06:36 +01:00 committed by Alex
parent b2250df119
commit 19fe23cbeb
2 changed files with 19 additions and 23 deletions

View file

@ -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<TagItem> for Option<Frame<'static>> {
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<TagItem> for Option<Frame<'static>> {
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<TagItem> for Option<Frame<'static>> {
{
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)) => {

View file

@ -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<Item = &LanguageFrame> {
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<Cow<'_, str>> {
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<ID3v2Tag> 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")
})
);