pub trait AsyncPaginatedIterator {
type Item;
// Required methods
async fn next(&mut self) -> Result<Option<Self::Item>>;
fn current_page(&self) -> u32;
// Provided methods
async fn collect_all(&mut self) -> Result<Vec<Self::Item>> { ... }
async fn take(&mut self, n: usize) -> Result<Vec<Self::Item>> { ... }
}Expand description
Async iterator trait for paginated Last.fm data.
This trait provides a common interface for iterating over paginated data from Last.fm, such as tracks, albums, and recent scrobbles. All iterators implement efficient streaming with automatic pagination and built-in rate limiting.
§Examples
use lastfm_edit::{LastFmEditClient, AsyncPaginatedIterator};
let mut client = LastFmEditClient::new(Box::new(http_client::native::NativeClient::new()));
// client.login(...).await?;
let mut tracks = client.artist_tracks("Radiohead");
// Iterate one by one
while let Some(track) = tracks.next().await? {
println!("{}", track.name);
}
// Or collect a limited number
let first_10 = tracks.take(10).await?;Required Associated Types§
Required Methods§
Sourceasync fn next(&mut self) -> Result<Option<Self::Item>>
async fn next(&mut self) -> Result<Option<Self::Item>>
Fetch the next item from the iterator.
This method automatically handles pagination, fetching new pages as needed.
Returns None when there are no more items available.
§Returns
Ok(Some(item))- Next item in the sequenceOk(None)- No more items availableErr(...)- Network or parsing error occurred
Sourcefn current_page(&self) -> u32
fn current_page(&self) -> u32
Get the current page number (0-indexed).
Returns the page number of the most recently fetched page.
Provided Methods§
Sourceasync fn collect_all(&mut self) -> Result<Vec<Self::Item>>
async fn collect_all(&mut self) -> Result<Vec<Self::Item>>
Collect all remaining items into a Vec.
Warning: This method will fetch ALL remaining pages, which could be
many thousands of items for large libraries. Use take for
safer bounded collection.
§Examples
let mut client = LastFmEditClient::new(Box::new(http_client::native::NativeClient::new()));
let mut tracks = client.artist_tracks("Small Artist");
let all_tracks = tracks.collect_all().await?;
println!("Found {} tracks total", all_tracks.len());Sourceasync fn take(&mut self, n: usize) -> Result<Vec<Self::Item>>
async fn take(&mut self, n: usize) -> Result<Vec<Self::Item>>
Take up to n items from the iterator.
This is the recommended way to collect a bounded number of items from potentially large datasets.
§Arguments
n- Maximum number of items to collect
§Examples
let mut client = LastFmEditClient::new(Box::new(http_client::native::NativeClient::new()));
let mut tracks = client.artist_tracks("Radiohead");
let top_20 = tracks.take(20).await?;
println!("Top 20 tracks: {:?}", top_20);Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.