into_iter -> items_iter

master
Paul Woolcock 6 years ago
parent 6d67e403bc
commit b4cbcfa1a7
  1. 2
      src/entities/mod.rs
  2. 30
      src/entities/pageiter.rs
  3. 6
      src/page.rs

@ -6,7 +6,7 @@ pub mod instance;
pub mod list; pub mod list;
pub mod mention; pub mod mention;
pub mod notification; pub mod notification;
mod pageiter; pub(crate) mod pageiter;
pub mod relationship; pub mod relationship;
pub mod report; pub mod report;
pub mod search_result; pub mod search_result;

@ -1,34 +1,6 @@
use page::Page; use page::Page;
use entities::{
account::Account,
notification::Notification,
relationship::Relationship,
report::Report,
status::{Emoji, Status}
};
use serde::Deserialize; use serde::Deserialize;
macro_rules! into_pageiter {
($typ:ty) => {
impl<'a> IntoIterator for Page<'a, $typ> {
type Item = $typ;
type IntoIter = PageIter<'a, $typ>;
fn into_iter(self) -> PageIter<'a, $typ> {
PageIter::new(self)
}
}
}
}
into_pageiter!(Status);
into_pageiter!(Account);
into_pageiter!(String);
into_pageiter!(Emoji);
into_pageiter!(Notification);
into_pageiter!(Report);
into_pageiter!(Relationship);
/// Abstracts away the `next_page` logic into a single stream of items /// Abstracts away the `next_page` logic into a single stream of items
/// ///
/// ```ignore /// ```ignore
@ -48,7 +20,7 @@ pub struct PageIter<'a, T: Clone + for<'de> Deserialize<'de>> {
} }
impl<'a, T: Clone + for<'de> Deserialize<'de>> PageIter<'a, T> { impl<'a, T: Clone + for<'de> Deserialize<'de>> PageIter<'a, T> {
fn new(page: Page<'a, T>) -> PageIter<'a, T> { pub(crate) fn new(page: Page<'a, T>) -> PageIter<'a, T> {
PageIter { PageIter {
page: page, page: page,
buffer: vec![], buffer: vec![],

@ -3,6 +3,7 @@ use reqwest::Response;
use reqwest::header::{Link, RelationType}; use reqwest::header::{Link, RelationType};
use serde::Deserialize; use serde::Deserialize;
use url::Url; use url::Url;
use entities::pageiter::PageIter;
pub struct Page<'a, T: for<'de> Deserialize<'de>> { pub struct Page<'a, T: for<'de> Deserialize<'de>> {
mastodon: &'a Mastodon, mastodon: &'a Mastodon,
@ -53,6 +54,11 @@ impl<'a, T: for<'de> Deserialize<'de>> Page<'a, T> {
} }
} }
impl<'a, T: Clone + for<'de> Deserialize<'de>> Page<'a, T> {
pub fn items_iter(self) -> PageIter<'a, T> {
PageIter::new(self)
}
}
fn get_links(response: &Response) -> Result<(Option<Url>, Option<Url>)> { fn get_links(response: &Response) -> Result<(Option<Url>, Option<Url>)> {
let mut prev = None; let mut prev = None;

Loading…
Cancel
Save