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). The first page’s own URL is not known here,
so a cycle back to it is caught one fetch later, when the refetched first page links on to
a page this paginator already fetched. For the same reason the origin every later page must
share is that of the seeded next link, the first URL this paginator fetches.
Sourcepub fn has_next(&self) -> bool
pub fn has_next(&self) -> bool
Whether the next Self::next_page call returns Some: a fetched page, or the error that
ends the chain, Error::PaginationCycle and Error::PaginationOriginChanged included.
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. Six things terminate the paginator (subsequent calls return None):
- a
nextURL whose scheme, host or port differs from the first URL this paginator fetched →Some(Err(Error::PaginationOriginChanged { from, to })), without sending a request. The page whose link left the origin was already yielded by the call before; - a
nextURL the paginator has already fetched (fragments aside) →Some(Err(Error::PaginationCycle { url })), itsurlwithout userinfo or query, without sending a request. The page whose link closed the cycle was already yielded by the call before; - a request for the
nextURL that cannot be built →Some(Err(Error::RequestConstruction(..))); - 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 this module’s 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.
Dropping the returned future before it resolves leaves the paginator as it was: still armed at the same URL, which the next call fetches again.
Auto Trait Implementations§
impl<T> !RefUnwindSafe for LinkPaginator<T>
impl<T> !UnwindSafe for LinkPaginator<T>
impl<T> Freeze for LinkPaginator<T>
impl<T> Send for LinkPaginator<T>
impl<T> Sync for LinkPaginator<T>
impl<T> Unpin for LinkPaginator<T>
impl<T> UnsafeUnpin for LinkPaginator<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more