pub struct ListIterator<T> { /* private fields */ }Expand description
A lazy, page-fetching async iterator over an offset/limit-paginated list endpoint.
Created by a collection client’s iterate() method. Each call to next
returns the next item, transparently fetching the following page from the API once the
local buffer drains, until the listing is exhausted (or the caller’s total-item cap is hit).
§limit vs. page size
The caller’s limit (from the list options passed to iterate()) is a cap on the total
number of items the iterator yields, matching the reference JavaScript client’s
_listPaginatedFromCallback, where options.limit bounds the whole async-iterable and a
separate chunkSize controls page size. Leaving limit unset (or 0) iterates the entire
listing. The page size is a distinct concern: set it with with_chunk_size;
when unset, the API’s default page size is used. So iterate(opts{ limit: 10 }) yields at most
10 items, and iterate(opts).with_chunk_size(50) fetches 50 per request while yielding
everything.
Large caps and the first page. When a total cap is set but no page size is, the first page
requests limit == cap (the reference client does the same, via
minForLimitParam(options.limit, options.chunkSize)). If you set a very large cap — larger
than the endpoint’s maximum limit — also call with_chunk_size with
a value at or below that maximum, so the first request stays within the endpoint’s accepted
range rather than asking for the whole cap up front.
§Example
use apify_client::ApifyClient;
let client = ApifyClient::new("my-api-token");
let mut it = client.actors().iterate(Default::default());
while let Some(actor) = it.next().await? {
println!("{}", actor.id);
}Implementations§
Source§impl<T> ListIterator<T>
impl<T> ListIterator<T>
Sourcepub fn with_chunk_size(self, chunk_size: i64) -> Self
pub fn with_chunk_size(self, chunk_size: i64) -> Self
Sets the page size (items requested per API call) for this iteration — the reference
client’s chunkSize. This controls only how many items each page fetch requests, never how
many the iterator yields in total (that is the caller’s limit; see the type docs). A
non-positive value lets the API choose its default page size.
Sourcepub async fn next(&mut self) -> ApifyClientResult<Option<T>>
pub async fn next(&mut self) -> ApifyClientResult<Option<T>>
Returns the next item, or None when the listing is exhausted. Fetches another page from
the API when the local buffer is empty.
Sourcepub async fn collect_all(self) -> ApifyClientResult<Vec<T>>
pub async fn collect_all(self) -> ApifyClientResult<Vec<T>>
Eagerly drains the iterator into a single Vec, fetching every remaining page.
Convenience for callers that want all items at once; prefer next to
process items as they stream in without buffering the whole result set.