into_iter -> items_iter
This commit is contained in:
+1
-1
@@ -6,7 +6,7 @@ pub mod instance;
|
||||
pub mod list;
|
||||
pub mod mention;
|
||||
pub mod notification;
|
||||
mod pageiter;
|
||||
pub(crate) mod pageiter;
|
||||
pub mod relationship;
|
||||
pub mod report;
|
||||
pub mod search_result;
|
||||
|
||||
@@ -1,34 +1,6 @@
|
||||
use page::Page;
|
||||
use entities::{
|
||||
account::Account,
|
||||
notification::Notification,
|
||||
relationship::Relationship,
|
||||
report::Report,
|
||||
status::{Emoji, Status}
|
||||
};
|
||||
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
|
||||
///
|
||||
/// ```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> {
|
||||
fn new(page: Page<'a, T>) -> PageIter<'a, T> {
|
||||
pub(crate) fn new(page: Page<'a, T>) -> PageIter<'a, T> {
|
||||
PageIter {
|
||||
page: page,
|
||||
buffer: vec![],
|
||||
|
||||
@@ -3,6 +3,7 @@ use reqwest::Response;
|
||||
use reqwest::header::{Link, RelationType};
|
||||
use serde::Deserialize;
|
||||
use url::Url;
|
||||
use entities::pageiter::PageIter;
|
||||
|
||||
pub struct Page<'a, T: for<'de> Deserialize<'de>> {
|
||||
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>)> {
|
||||
let mut prev = None;
|
||||
|
||||
Reference in New Issue
Block a user