pub struct Page<T: for<'de> Deserialize<'de> + Serialize> {
pub next: Option<Url>,
pub prev: Option<Url>,
pub initial_items: Vec<T>,
/* private fields */
}Expand description
Owned version of the Page struct in this module. Allows this to be more
easily stored for later use
// Example
use mastodon_async::{
prelude::*,
page::Page,
entities::status::Status
};
use std::cell::RefCell;
tokio_test::block_on(async {
let data = Data::default();
struct HomeTimeline {
client: Mastodon,
page: RefCell<Option<Page<Status>>>,
}
let client = Mastodon::from(data);
let home = client.get_home_timeline().await.unwrap();
let tl = HomeTimeline {
client,
page: RefCell::new(Some(home)),
};
});Represents a single page of API results
Fields§
§next: Option<Url>next url
prev: Option<Url>prev url
initial_items: Vec<T>Initial set of items
Implementations§
Source§impl<'a, T: for<'de> Deserialize<'de> + Serialize> Page<T>
impl<'a, T: for<'de> Deserialize<'de> + Serialize> Page<T>
Sourcepub async fn next_page(&mut self) -> Result<Option<Vec<T>>>
pub async fn next_page(&mut self) -> Result<Option<Vec<T>>>
Method to retrieve the next page of resultsReturns Ok(None) if there is no data in the next page.
Returns Ok(Some(Vec
Sourcepub async fn prev_page(&mut self) -> Result<Option<Vec<T>>>
pub async fn prev_page(&mut self) -> Result<Option<Vec<T>>>
Method to retrieve the prev page of resultsReturns Ok(None) if there is no data in the prev page.
Returns Ok(Some(Vec
Source§impl<T: Clone + for<'de> Deserialize<'de> + Serialize> Page<T>
impl<T: Clone + for<'de> Deserialize<'de> + Serialize> Page<T>
Sourcepub fn items_iter(self) -> impl Stream<Item = T>
pub fn items_iter(self) -> impl Stream<Item = T>
Returns an iterator that provides a stream of Ts
This abstracts away the process of iterating over each item in a page,
then making an http call, then iterating over each item in the new
page, etc. The iterator provides a stream of Ts, calling
self.next_page()
when necessary to get
more of them, until
there are no more items.
// Example
use mastodon_async::prelude::*;
use futures_util::StreamExt;
let data = Data::default();
let mastodon = Mastodon::from(data);
let req = StatusesRequest::new();
tokio_test::block_on(async {
let resp = mastodon.statuses(&AccountId::new("some-id"), req).await.unwrap();
resp.items_iter().for_each(|status| async move {
// do something with status
}).await;
});