pub trait AsyncPaginatedIterator<T> {
// Required methods
fn next<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait;
fn current_page(&self) -> u32;
// Provided methods
fn collect_all<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn take<'life0, 'async_trait>(
&'life0 mut self,
n: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait { ... }
fn total_pages(&self) -> Option<u32> { ... }
}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.
Required Methods§
Sourcefn next<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn next<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Option<T>>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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§
Sourcefn collect_all<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn collect_all<'life0, 'async_trait>(
&'life0 mut self,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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.
Sourcefn take<'life0, 'async_trait>(
&'life0 mut self,
n: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn take<'life0, 'async_trait>(
&'life0 mut self,
n: usize,
) -> Pin<Box<dyn Future<Output = Result<Vec<T>>> + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
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
Sourcefn total_pages(&self) -> Option<u32>
fn total_pages(&self) -> Option<u32>
Get the total number of pages, if known.
Returns Some(n) if the total page count is known, None otherwise.
This information may not be available until at least one page has been fetched.