diff --git a/examples/playlist_tracks.rs b/examples/playlist_tracks.rs index 7404e755..c2cf419a 100644 --- a/examples/playlist_tracks.rs +++ b/examples/playlist_tracks.rs @@ -36,7 +36,7 @@ async fn main() { let plist = Playlist::get(&session, plist_uri).await.unwrap(); println!("{:?}", plist); for track_id in plist.tracks() { - let plist_track = Track::get(&session, track_id).await.unwrap(); + let plist_track = Track::get(&session, *track_id).await.unwrap(); println!("track: {} ", plist_track.name); } } diff --git a/metadata/src/album.rs b/metadata/src/album.rs index 85bee013..c2c439c2 100644 --- a/metadata/src/album.rs +++ b/metadata/src/album.rs @@ -67,13 +67,8 @@ pub struct Discs(pub Vec); impl_deref_wrapped!(Discs, Vec); impl Album { - pub fn tracks(&self) -> Tracks { - let result = self - .discs - .iter() - .flat_map(|disc| disc.tracks.deref().clone()) - .collect(); - Tracks(result) + pub fn tracks(&self) -> impl Iterator { + self.discs.iter().flat_map(|disc| disc.tracks.iter()) } } diff --git a/metadata/src/artist.rs b/metadata/src/artist.rs index 7ddf07a1..db297b59 100644 --- a/metadata/src/artist.rs +++ b/metadata/src/artist.rs @@ -140,14 +140,14 @@ impl Artist { /// Get the full list of albums, not containing duplicate variants of the same albums. /// /// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`] - pub fn albums_current(&self) -> Albums { + pub fn albums_current(&self) -> impl Iterator { self.albums.current_releases() } /// Get the full list of singles, not containing duplicate variants of the same singles. /// /// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`] - pub fn singles_current(&self) -> Albums { + pub fn singles_current(&self) -> impl Iterator { self.singles.current_releases() } @@ -155,14 +155,14 @@ impl Artist { /// compilations. /// /// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`] - pub fn compilations_current(&self) -> Albums { + pub fn compilations_current(&self) -> impl Iterator { self.compilations.current_releases() } /// Get the full list of albums, not containing duplicate variants of the same albums. /// /// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`] - pub fn appears_on_albums_current(&self) -> Albums { + pub fn appears_on_albums_current(&self) -> impl Iterator { self.appears_on_albums.current_releases() } } @@ -245,13 +245,8 @@ impl AlbumGroups { /// Get the contained albums. This will only use the latest release / variant of an album if /// multiple variants are available. This should be used if multiple variants of the same album /// are not explicitely desired. - pub fn current_releases(&self) -> Albums { - let albums = self - .iter() - .filter_map(|agrp| agrp.first()) - .cloned() - .collect(); - Albums(albums) + pub fn current_releases(&self) -> impl Iterator { + self.iter().filter_map(|agrp| agrp.first()) } } diff --git a/metadata/src/playlist/list.rs b/metadata/src/playlist/list.rs index 223f8d30..300c0c09 100644 --- a/metadata/src/playlist/list.rs +++ b/metadata/src/playlist/list.rs @@ -105,13 +105,8 @@ impl Playlist { Self::parse(&msg, playlist_id) } - pub fn tracks(&self) -> Vec { - let tracks = self - .contents - .items - .iter() - .map(|item| item.id) - .collect::>(); + pub fn tracks(&self) -> impl ExactSizeIterator { + let tracks = self.contents.items.iter().map(|item| &item.id); let length = tracks.len(); let expected_length = self.length as usize;