Skip to main content

ListIterator

Struct ListIterator 

Source
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>

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

§

impl<T> !RefUnwindSafe for ListIterator<T>

§

impl<T> !UnwindSafe for ListIterator<T>

§

impl<T> Freeze for ListIterator<T>

§

impl<T> Send for ListIterator<T>
where T: Send,

§

impl<T> Sync for ListIterator<T>
where T: Sync,

§

impl<T> Unpin for ListIterator<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ListIterator<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more