mirror of
https://github.com/librespot-org/librespot.git
synced 2024-12-18 17:11:53 +00:00
Merge pull request #1040 from dnlmlr/metadata-iterators-instead-of-vecs
Return iterators instead of collected Vecs
This commit is contained in:
commit
b2c7b25835
4 changed files with 11 additions and 26 deletions
|
@ -36,7 +36,7 @@ async fn main() {
|
||||||
let plist = Playlist::get(&session, plist_uri).await.unwrap();
|
let plist = Playlist::get(&session, plist_uri).await.unwrap();
|
||||||
println!("{:?}", plist);
|
println!("{:?}", plist);
|
||||||
for track_id in plist.tracks() {
|
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);
|
println!("track: {} ", plist_track.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -67,13 +67,8 @@ pub struct Discs(pub Vec<Disc>);
|
||||||
impl_deref_wrapped!(Discs, Vec<Disc>);
|
impl_deref_wrapped!(Discs, Vec<Disc>);
|
||||||
|
|
||||||
impl Album {
|
impl Album {
|
||||||
pub fn tracks(&self) -> Tracks {
|
pub fn tracks(&self) -> impl Iterator<Item = &SpotifyId> {
|
||||||
let result = self
|
self.discs.iter().flat_map(|disc| disc.tracks.iter())
|
||||||
.discs
|
|
||||||
.iter()
|
|
||||||
.flat_map(|disc| disc.tracks.deref().clone())
|
|
||||||
.collect();
|
|
||||||
Tracks(result)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -140,14 +140,14 @@ impl Artist {
|
||||||
/// Get the full list of albums, not containing duplicate variants of the same albums.
|
/// Get the full list of albums, not containing duplicate variants of the same albums.
|
||||||
///
|
///
|
||||||
/// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`]
|
/// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`]
|
||||||
pub fn albums_current(&self) -> Albums {
|
pub fn albums_current(&self) -> impl Iterator<Item = &SpotifyId> {
|
||||||
self.albums.current_releases()
|
self.albums.current_releases()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the full list of singles, not containing duplicate variants of the same singles.
|
/// Get the full list of singles, not containing duplicate variants of the same singles.
|
||||||
///
|
///
|
||||||
/// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`]
|
/// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`]
|
||||||
pub fn singles_current(&self) -> Albums {
|
pub fn singles_current(&self) -> impl Iterator<Item = &SpotifyId> {
|
||||||
self.singles.current_releases()
|
self.singles.current_releases()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,14 +155,14 @@ impl Artist {
|
||||||
/// compilations.
|
/// compilations.
|
||||||
///
|
///
|
||||||
/// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`]
|
/// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`]
|
||||||
pub fn compilations_current(&self) -> Albums {
|
pub fn compilations_current(&self) -> impl Iterator<Item = &SpotifyId> {
|
||||||
self.compilations.current_releases()
|
self.compilations.current_releases()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Get the full list of albums, not containing duplicate variants of the same albums.
|
/// Get the full list of albums, not containing duplicate variants of the same albums.
|
||||||
///
|
///
|
||||||
/// See also [`AlbumGroups`](struct@AlbumGroups) and [`AlbumGroups::current_releases`]
|
/// 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<Item = &SpotifyId> {
|
||||||
self.appears_on_albums.current_releases()
|
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
|
/// 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
|
/// multiple variants are available. This should be used if multiple variants of the same album
|
||||||
/// are not explicitely desired.
|
/// are not explicitely desired.
|
||||||
pub fn current_releases(&self) -> Albums {
|
pub fn current_releases(&self) -> impl Iterator<Item = &SpotifyId> {
|
||||||
let albums = self
|
self.iter().filter_map(|agrp| agrp.first())
|
||||||
.iter()
|
|
||||||
.filter_map(|agrp| agrp.first())
|
|
||||||
.cloned()
|
|
||||||
.collect();
|
|
||||||
Albums(albums)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,13 +105,8 @@ impl Playlist {
|
||||||
Self::parse(&msg, playlist_id)
|
Self::parse(&msg, playlist_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tracks(&self) -> Vec<SpotifyId> {
|
pub fn tracks(&self) -> impl ExactSizeIterator<Item = &SpotifyId> {
|
||||||
let tracks = self
|
let tracks = self.contents.items.iter().map(|item| &item.id);
|
||||||
.contents
|
|
||||||
.items
|
|
||||||
.iter()
|
|
||||||
.map(|item| item.id)
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let length = tracks.len();
|
let length = tracks.len();
|
||||||
let expected_length = self.length as usize;
|
let expected_length = self.length as usize;
|
||||||
|
|
Loading…
Reference in a new issue