pub struct Paginator<T: Paginated> { /* private fields */ }Expand description
Async auto-paginator returned by Client::paginate.
next_page is a plain cursor, with no dependency on futures:
use datamaxi::api::ClientBuilder;
use datamaxi::CexAnnouncementsResponse;
use std::collections::BTreeMap;
let client = ClientBuilder::new().api_key("my_api_key").build()?;
let mut pages = client
.paginate::<CexAnnouncementsResponse>("/api/v1/cex/announcements", BTreeMap::new());
while let Some(items) = pages.next_page().await? {
for item in items {
println!("{}", item.title);
}
}With the opt-in stream feature, Paginator also implements
Stream
(the trait re-exported as futures::Stream by the
futures crate), yielding one
Result<Vec<T::Item>> per page, so it composes with futures/StreamExt
combinators and .next().await:
use datamaxi::api::ClientBuilder;
use datamaxi::CexAnnouncementsResponse;
use futures::StreamExt;
use std::collections::BTreeMap;
let client = ClientBuilder::new().api_key("my_api_key").build()?;
let mut pages = client
.paginate::<CexAnnouncementsResponse>("/api/v1/cex/announcements", BTreeMap::new());
while let Some(page) = pages.next().await {
for item in page? {
println!("{}", item.title);
}
}Implementations§
Source§impl<T> Paginator<T>where
T: Paginated + DeserializeOwned,
impl<T> Paginator<T>where
T: Paginated + DeserializeOwned,
Sourcepub async fn next_page(&mut self) -> Result<Option<Vec<T::Item>>>
pub async fn next_page(&mut self) -> Result<Option<Vec<T::Item>>>
Fetches and returns the next page’s items, or Ok(None) once the
server has no more data: an empty page, or (when the envelope reports
a total) a page reaching page * limit >= total. Once exhausted,
further calls keep returning Ok(None) rather than re-fetching.
Auto Trait Implementations§
impl<T> Freeze for Paginator<T>
impl<T> !RefUnwindSafe for Paginator<T>
impl<T> Send for Paginator<T>where
T: Send,
impl<T> Sync for Paginator<T>where
T: Sync,
impl<T> Unpin for Paginator<T>where
T: Unpin,
impl<T> UnsafeUnpin for Paginator<T>
impl<T> !UnwindSafe for Paginator<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
Mutably borrows from an owned value. Read more