mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2025-01-07 17:58:45 +00:00
id3v2: Change const fn
into const
This commit is contained in:
parent
b2250df119
commit
19fe23cbeb
2 changed files with 19 additions and 23 deletions
|
@ -26,9 +26,7 @@ use std::hash::{Hash, Hasher};
|
||||||
/// are supposed to have an empty content descriptor. Only those
|
/// are supposed to have an empty content descriptor. Only those
|
||||||
/// are currently supported as [`TagItem`]s to avoid ambiguities
|
/// are currently supported as [`TagItem`]s to avoid ambiguities
|
||||||
/// and to prevent inconsistencies when writing them.
|
/// and to prevent inconsistencies when writing them.
|
||||||
pub(super) const fn empty_content_descriptor() -> String {
|
pub(super) const EMPTY_CONTENT_DESCRIPTOR: String = String::new();
|
||||||
String::new()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Unknown language-aware text frame
|
/// Unknown language-aware text frame
|
||||||
///
|
///
|
||||||
|
@ -295,7 +293,7 @@ impl From<TagItem> for Option<Frame<'static>> {
|
||||||
FrameValue::Comment(LanguageFrame {
|
FrameValue::Comment(LanguageFrame {
|
||||||
encoding: TextEncoding::UTF8,
|
encoding: TextEncoding::UTF8,
|
||||||
language: UNKNOWN_LANGUAGE,
|
language: UNKNOWN_LANGUAGE,
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: text,
|
content: text,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -303,7 +301,7 @@ impl From<TagItem> for Option<Frame<'static>> {
|
||||||
FrameValue::UnSyncText(LanguageFrame {
|
FrameValue::UnSyncText(LanguageFrame {
|
||||||
encoding: TextEncoding::UTF8,
|
encoding: TextEncoding::UTF8,
|
||||||
language: UNKNOWN_LANGUAGE,
|
language: UNKNOWN_LANGUAGE,
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: text,
|
content: text,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -312,14 +310,14 @@ impl From<TagItem> for Option<Frame<'static>> {
|
||||||
{
|
{
|
||||||
FrameValue::UserURL(EncodedTextFrame {
|
FrameValue::UserURL(EncodedTextFrame {
|
||||||
encoding: TextEncoding::UTF8,
|
encoding: TextEncoding::UTF8,
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: text,
|
content: text,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
(FrameID::Valid(ref s), ItemValue::Text(text)) if s == "TXXX" => {
|
(FrameID::Valid(ref s), ItemValue::Text(text)) if s == "TXXX" => {
|
||||||
FrameValue::UserText(EncodedTextFrame {
|
FrameValue::UserText(EncodedTextFrame {
|
||||||
encoding: TextEncoding::UTF8,
|
encoding: TextEncoding::UTF8,
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: text,
|
content: text,
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
@ -403,25 +401,25 @@ impl<'a> TryFrom<&'a TagItem> for FrameRef<'a> {
|
||||||
("COMM", ItemValue::Text(text)) => FrameValue::Comment(LanguageFrame {
|
("COMM", ItemValue::Text(text)) => FrameValue::Comment(LanguageFrame {
|
||||||
encoding: TextEncoding::UTF8,
|
encoding: TextEncoding::UTF8,
|
||||||
language: UNKNOWN_LANGUAGE,
|
language: UNKNOWN_LANGUAGE,
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: text.clone(),
|
content: text.clone(),
|
||||||
}),
|
}),
|
||||||
("USLT", ItemValue::Text(text)) => FrameValue::UnSyncText(LanguageFrame {
|
("USLT", ItemValue::Text(text)) => FrameValue::UnSyncText(LanguageFrame {
|
||||||
encoding: TextEncoding::UTF8,
|
encoding: TextEncoding::UTF8,
|
||||||
language: UNKNOWN_LANGUAGE,
|
language: UNKNOWN_LANGUAGE,
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: text.clone(),
|
content: text.clone(),
|
||||||
}),
|
}),
|
||||||
("WXXX", ItemValue::Locator(text) | ItemValue::Text(text)) => {
|
("WXXX", ItemValue::Locator(text) | ItemValue::Text(text)) => {
|
||||||
FrameValue::UserURL(EncodedTextFrame {
|
FrameValue::UserURL(EncodedTextFrame {
|
||||||
encoding: TextEncoding::UTF8,
|
encoding: TextEncoding::UTF8,
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: text.clone(),
|
content: text.clone(),
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
("TXXX", ItemValue::Text(text)) => FrameValue::UserText(EncodedTextFrame {
|
("TXXX", ItemValue::Text(text)) => FrameValue::UserText(EncodedTextFrame {
|
||||||
encoding: TextEncoding::UTF8,
|
encoding: TextEncoding::UTF8,
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: text.clone(),
|
content: text.clone(),
|
||||||
}),
|
}),
|
||||||
("POPM", ItemValue::Binary(contents)) => {
|
("POPM", ItemValue::Binary(contents)) => {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use super::flags::ID3v2TagFlags;
|
use super::flags::ID3v2TagFlags;
|
||||||
use super::frame::id::FrameID;
|
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 super::ID3v2Version;
|
||||||
use crate::error::{LoftyError, Result};
|
use crate::error::{LoftyError, Result};
|
||||||
use crate::id3::v2::frame::FrameRef;
|
use crate::id3::v2::frame::FrameRef;
|
||||||
|
@ -283,7 +283,7 @@ impl ID3v2Tag {
|
||||||
/// Returns all `COMM` frames with an empty content descriptor
|
/// Returns all `COMM` frames with an empty content descriptor
|
||||||
pub fn comments(&self) -> impl Iterator<Item = &LanguageFrame> {
|
pub fn comments(&self) -> impl Iterator<Item = &LanguageFrame> {
|
||||||
self.frames.iter().filter_map(|frame| {
|
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>> {
|
fn comment(&self) -> Option<Cow<'_, str>> {
|
||||||
self.frames
|
self.frames
|
||||||
.iter()
|
.iter()
|
||||||
.find_map(|frame| {
|
.find_map(|frame| filter_comment_frame_by_description(frame, &EMPTY_CONTENT_DESCRIPTOR))
|
||||||
filter_comment_frame_by_description(frame, &empty_content_descriptor())
|
|
||||||
})
|
|
||||||
.map(|LanguageFrame { content, .. }| Cow::Borrowed(content.as_str()))
|
.map(|LanguageFrame { content, .. }| Cow::Borrowed(content.as_str()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,7 +444,7 @@ impl Accessor for ID3v2Tag {
|
||||||
.frames
|
.frames
|
||||||
.iter_mut()
|
.iter_mut()
|
||||||
.find_map(|frame| {
|
.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)
|
.map(|LanguageFrame { content, .. }| content)
|
||||||
{
|
{
|
||||||
|
@ -459,7 +457,7 @@ impl Accessor for ID3v2Tag {
|
||||||
value: FrameValue::Comment(LanguageFrame {
|
value: FrameValue::Comment(LanguageFrame {
|
||||||
encoding: TextEncoding::UTF8,
|
encoding: TextEncoding::UTF8,
|
||||||
language: UNKNOWN_LANGUAGE,
|
language: UNKNOWN_LANGUAGE,
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: value,
|
content: value,
|
||||||
}),
|
}),
|
||||||
flags: FrameFlags::default(),
|
flags: FrameFlags::default(),
|
||||||
|
@ -468,7 +466,7 @@ impl Accessor for ID3v2Tag {
|
||||||
|
|
||||||
fn remove_comment(&mut self) {
|
fn remove_comment(&mut self) {
|
||||||
self.frames.retain(|frame| {
|
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,
|
description,
|
||||||
..
|
..
|
||||||
}) => {
|
}) => {
|
||||||
if description == empty_content_descriptor() {
|
if description == EMPTY_CONTENT_DESCRIPTOR {
|
||||||
for c in content.split(V4_MULTI_VALUE_SEPARATOR) {
|
for c in content.split(V4_MULTI_VALUE_SEPARATOR) {
|
||||||
tag.items.push(TagItem::new(
|
tag.items.push(TagItem::new(
|
||||||
item_key.clone(),
|
item_key.clone(),
|
||||||
|
@ -806,7 +804,7 @@ mod tests {
|
||||||
Accessor, ItemKey, ItemValue, MimeType, Picture, PictureType, Tag, TagExt, TagItem, TagType,
|
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 {
|
fn read_tag(path: &str) -> ID3v2Tag {
|
||||||
let tag_bytes = crate::tag::utils::test_utils::read_path(path);
|
let tag_bytes = crate::tag::utils::test_utils::read_path(path);
|
||||||
|
@ -866,7 +864,7 @@ mod tests {
|
||||||
FrameValue::Comment(LanguageFrame {
|
FrameValue::Comment(LanguageFrame {
|
||||||
encoding,
|
encoding,
|
||||||
language: *b"eng",
|
language: *b"eng",
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: String::from("Qux comment"),
|
content: String::from("Qux comment"),
|
||||||
}),
|
}),
|
||||||
flags,
|
flags,
|
||||||
|
@ -1043,7 +1041,7 @@ mod tests {
|
||||||
&FrameValue::Comment(LanguageFrame {
|
&FrameValue::Comment(LanguageFrame {
|
||||||
encoding: TextEncoding::Latin1,
|
encoding: TextEncoding::Latin1,
|
||||||
language: *b"eng",
|
language: *b"eng",
|
||||||
description: empty_content_descriptor(),
|
description: EMPTY_CONTENT_DESCRIPTOR,
|
||||||
content: String::from("Qux comment")
|
content: String::from("Qux comment")
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
Loading…
Reference in a new issue