Page

Struct Page 

Source
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>

Source

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)) if there are results. Returns Err(Error) if there is an error. If there are results, the next and previous page urls are stored. If there are no results, the next and previous page urls are not stored. This allows for the next page to be retrieved in the future even when there are no results.

Source

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)) if there are results. Returns Err(Error) if there is an error. If there are results, the next and previous page urls are stored. If there are no results, the next and previous page urls are not stored. This allows for the next page to be retrieved in the future even when there are no results.

Source§

impl<T: Clone + for<'de> Deserialize<'de> + Serialize> Page<T>

Source

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;
});

Trait Implementations§

Source§

impl<T: Clone + for<'de> Deserialize<'de> + Serialize> Clone for Page<T>

Source§

fn clone(&self) -> Page<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + for<'de> Deserialize<'de> + Serialize> Debug for Page<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Page<T>

§

impl<T> !RefUnwindSafe for Page<T>

§

impl<T> Send for Page<T>
where T: Send,

§

impl<T> Sync for Page<T>
where T: Sync,

§

impl<T> Unpin for Page<T>
where T: Unpin,

§

impl<T> !UnwindSafe for Page<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more