pub struct TokenPager { /* private fields */ }Expand description
Walks every page of GET /tokens, one request at a time.
Built with FyuzClient::token_pages. The pager starts at the page in the
ListTokensParams it was given (or page 1) and stops as soon as the
server’s tokenCount is covered or a page comes back empty — so it
terminates even if the total shifts while you are walking it.
This is a plain async iterator rather than a futures::Stream: the crate
has no futures dependency, and while let Some(..) = pager.next_*().await?
reads the same.
use fyuz::{FyuzClient, ListTokensParams, SortDirection};
let client = FyuzClient::new()?;
let mut pager = client.token_pages(
&ListTokensParams::new()
.order_type("marketcap")
.order_flag(SortDirection::Desc)
.page_size(100),
);
// Page at a time…
while let Some(page) = pager.next_page().await? {
println!("{} tokens (of {:?} total)", page.len(), pager.total_count());
}// …or token at a time, with paging handled underneath.
let mut pager = client.token_pages(&ListTokensParams::new());
while let Some(token) = pager.next_token().await? {
println!("{}", token.token_symbol);
}Implementations§
Source§impl TokenPager
impl TokenPager
Sourcepub fn total_count(&self) -> Option<i64>
pub fn total_count(&self) -> Option<i64>
Total matching rows, as reported by the last page fetched. None before
the first request.
Sourcepub fn fetched_count(&self) -> i64
pub fn fetched_count(&self) -> i64
Rows yielded so far.
Sourcepub async fn next_page(&mut self) -> Result<Option<Vec<Token>>>
pub async fn next_page(&mut self) -> Result<Option<Vec<Token>>>
Fetch the next page. Returns None once every page has been walked.
Sourcepub async fn next_token(&mut self) -> Result<Option<Token>>
pub async fn next_token(&mut self) -> Result<Option<Token>>
Yield the next token, fetching a page whenever the buffer runs dry.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for TokenPager
impl !UnwindSafe for TokenPager
impl Freeze for TokenPager
impl Send for TokenPager
impl Sync for TokenPager
impl Unpin for TokenPager
impl UnsafeUnpin for TokenPager
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