mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-14 22:52:32 +00:00
Let Tag::items() return an iterator
This commit is contained in:
parent
31894bedfc
commit
100b7e21b1
4 changed files with 24 additions and 20 deletions
|
@ -396,8 +396,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tagitems_into_ape(items: &[TagItem]) -> impl Iterator<Item = ApeItemRef<'_>> {
|
pub(crate) fn tagitems_into_ape<'a>(
|
||||||
items.iter().filter_map(|i| {
|
items: impl IntoIterator<Item = &'a TagItem>,
|
||||||
|
) -> impl Iterator<Item = ApeItemRef<'a>> {
|
||||||
|
items.into_iter().filter_map(|i| {
|
||||||
i.key().map_key(TagType::APE, true).map(|key| ApeItemRef {
|
i.key().map_key(TagType::APE, true).map(|key| ApeItemRef {
|
||||||
read_only: false,
|
read_only: false,
|
||||||
key,
|
key,
|
||||||
|
|
|
@ -694,7 +694,6 @@ impl<'a> Id3v2TagRef<'a, std::iter::Empty<FrameRef<'a>>> {
|
||||||
pub(crate) fn tag_frames(tag: &Tag) -> impl Iterator<Item = FrameRef<'_>> + Clone {
|
pub(crate) fn tag_frames(tag: &Tag) -> impl Iterator<Item = FrameRef<'_>> + Clone {
|
||||||
let items = tag
|
let items = tag
|
||||||
.items()
|
.items()
|
||||||
.iter()
|
|
||||||
.map(TryInto::<FrameRef<'_>>::try_into)
|
.map(TryInto::<FrameRef<'_>>::try_into)
|
||||||
.filter_map(Result::ok);
|
.filter_map(Result::ok);
|
||||||
|
|
||||||
|
@ -1263,19 +1262,20 @@ mod tests {
|
||||||
let tag: Tag = tag.into();
|
let tag: Tag = tag.into();
|
||||||
|
|
||||||
assert_eq!(tag.item_count(), 2);
|
assert_eq!(tag.item_count(), 2);
|
||||||
assert_eq!(
|
let expected_items = [
|
||||||
tag.items(),
|
TagItem::new(
|
||||||
&[
|
ItemKey::Unknown(String::from("FOO_TEXT_FRAME")),
|
||||||
TagItem::new(
|
ItemValue::Text(String::from("foo content")),
|
||||||
ItemKey::Unknown(String::from("FOO_TEXT_FRAME")),
|
),
|
||||||
ItemValue::Text(String::from("foo content"))
|
TagItem::new(
|
||||||
),
|
ItemKey::Unknown(String::from("BAR_URL_FRAME")),
|
||||||
TagItem::new(
|
ItemValue::Locator(String::from("bar url")),
|
||||||
ItemKey::Unknown(String::from("BAR_URL_FRAME")),
|
),
|
||||||
ItemValue::Locator(String::from("bar url"))
|
];
|
||||||
),
|
assert!(expected_items
|
||||||
]
|
.iter()
|
||||||
);
|
.zip(tag.items())
|
||||||
|
.all(|(expected, actual)| expected == actual));
|
||||||
|
|
||||||
let tag: ID3v2Tag = tag.into();
|
let tag: ID3v2Tag = tag.into();
|
||||||
|
|
||||||
|
|
|
@ -259,8 +259,10 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn tagitems_into_riff(items: &[TagItem]) -> impl Iterator<Item = (&str, &str)> + Clone {
|
pub(crate) fn tagitems_into_riff<'a>(
|
||||||
items.iter().filter_map(|i| {
|
items: impl IntoIterator<Item = &'a TagItem>,
|
||||||
|
) -> impl Iterator<Item = (&'a str, &'a str)> {
|
||||||
|
items.into_iter().filter_map(|i| {
|
||||||
let item_key = i.key().map_key(TagType::RIFFInfo, true);
|
let item_key = i.key().map_key(TagType::RIFFInfo, true);
|
||||||
|
|
||||||
match (item_key, i.value()) {
|
match (item_key, i.value()) {
|
||||||
|
|
|
@ -247,8 +247,8 @@ impl Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the stored [`TagItem`]s as a slice
|
/// Returns the stored [`TagItem`]s as a slice
|
||||||
pub fn items(&self) -> &[TagItem] {
|
pub fn items(&self) -> impl Iterator<Item = &TagItem> + Clone {
|
||||||
&self.items
|
self.items.iter()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a reference to a [`TagItem`] matching an [`ItemKey`]
|
/// Returns a reference to a [`TagItem`] matching an [`ItemKey`]
|
||||||
|
|
Loading…
Reference in a new issue