pub struct LinkPaginator<T> { /* private fields */ }Expand description
A manual async iterator over the pages of a Link-header-paginated collection.
Holds the [ClientCore] and the URL of the next page to fetch (if any). Each Self::next_page
GETs the current URL, decodes its body as T, reads the response’s Link: <…>; rel="next"
header to find the following page, and yields the decoded page. It returns None once a response
carries no rel="next" link — or after any error, which terminates the paginator.
T is the decoded body type of one page: typically a Vec<Item> for an array collection, or a
wrapper struct whose fields include the items. Dropping the paginator is safe (standard HTTP drop
semantics).
Implementations§
Source§impl<T> LinkPaginator<T>
impl<T> LinkPaginator<T>
Sourcepub fn new(core: ClientCore, first: Url) -> Self
pub fn new(core: ClientCore, first: Url) -> Self
Seed a paginator from the URL of the first page. No request is made until the first
Self::next_page call.
Sourcepub fn from_headers(core: ClientCore, headers: &HeaderMap) -> Self
pub fn from_headers(core: ClientCore, headers: &HeaderMap) -> Self
Seed a paginator from the headers of an already-fetched first response (the rel="next"
link), so a caller who fetched page one through a normal operation method can continue from
its headers. Only an absolute next URL is followed; a relative one yields no next page (use
Self::new with the resolved URL instead).
Sourcepub fn has_next(&self) -> bool
pub fn has_next(&self) -> bool
Whether another page will be fetched by the next Self::next_page call.
Source§impl<T: DeserializeOwned> LinkPaginator<T>
impl<T: DeserializeOwned> LinkPaginator<T>
Sourcepub async fn next_page(
&mut self,
) -> Option<Result<ResponseValue<T>, Error<Infallible>>>
pub async fn next_page( &mut self, ) -> Option<Result<ResponseValue<T>, Error<Infallible>>>
Fetch and decode the next page, or return None at the end of the chain.
GETs the current next URL, parses its response Link header for rel="next" (resolving a
relative target against the fetched URL) to arm the following page, then decodes the body as
T. Three things terminate the paginator (subsequent calls return None):
- a transport failure →
Some(Err(..)); - a non-success HTTP status (anything outside
2xx) →Some(Err(Error::UnexpectedStatus))— the body is never decoded asT, so an error payload can’t masquerade as a page. The generic paginator has no per-operation error taxonomy, and it attaches no per-operation credentials, so a follow-up page that401s (see the auth caveat in the module docs) surfaces here rather than being silently mis-decoded; - a decode failure on a
2xxbody →Some(Err(Error::Decode)).
When a 2xx page carries no rel="next" link, the page is yielded and the following call
returns None.