mirror of
https://github.com/Serial-ATA/lofty-rs
synced 2024-12-14 14:42:33 +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<'_>> {
|
||||
items.iter().filter_map(|i| {
|
||||
pub(crate) fn tagitems_into_ape<'a>(
|
||||
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 {
|
||||
read_only: false,
|
||||
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 {
|
||||
let items = tag
|
||||
.items()
|
||||
.iter()
|
||||
.map(TryInto::<FrameRef<'_>>::try_into)
|
||||
.filter_map(Result::ok);
|
||||
|
||||
|
@ -1263,19 +1262,20 @@ mod tests {
|
|||
let tag: Tag = tag.into();
|
||||
|
||||
assert_eq!(tag.item_count(), 2);
|
||||
assert_eq!(
|
||||
tag.items(),
|
||||
&[
|
||||
let expected_items = [
|
||||
TagItem::new(
|
||||
ItemKey::Unknown(String::from("FOO_TEXT_FRAME")),
|
||||
ItemValue::Text(String::from("foo content"))
|
||||
ItemValue::Text(String::from("foo content")),
|
||||
),
|
||||
TagItem::new(
|
||||
ItemKey::Unknown(String::from("BAR_URL_FRAME")),
|
||||
ItemValue::Locator(String::from("bar url"))
|
||||
ItemValue::Locator(String::from("bar url")),
|
||||
),
|
||||
]
|
||||
);
|
||||
];
|
||||
assert!(expected_items
|
||||
.iter()
|
||||
.zip(tag.items())
|
||||
.all(|(expected, actual)| expected == actual));
|
||||
|
||||
let tag: ID3v2Tag = tag.into();
|
||||
|
||||
|
|
|
@ -259,8 +259,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
pub(crate) fn tagitems_into_riff(items: &[TagItem]) -> impl Iterator<Item = (&str, &str)> + Clone {
|
||||
items.iter().filter_map(|i| {
|
||||
pub(crate) fn tagitems_into_riff<'a>(
|
||||
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);
|
||||
|
||||
match (item_key, i.value()) {
|
||||
|
|
|
@ -247,8 +247,8 @@ impl Tag {
|
|||
}
|
||||
|
||||
/// Returns the stored [`TagItem`]s as a slice
|
||||
pub fn items(&self) -> &[TagItem] {
|
||||
&self.items
|
||||
pub fn items(&self) -> impl Iterator<Item = &TagItem> + Clone {
|
||||
self.items.iter()
|
||||
}
|
||||
|
||||
/// Returns a reference to a [`TagItem`] matching an [`ItemKey`]
|
||||
|
|
Loading…
Reference in a new issue