Change `PageIter` to `ItemsIter`

master
Paul Woolcock 6 years ago
parent 68f8766aff
commit 6501470312
  1. 10
      src/entities/itemsiter.rs
  2. 3
      src/entities/mod.rs
  3. 8
      src/page.rs

@ -12,16 +12,16 @@ use serde::Deserialize;
/// // do something with `status` /// // do something with `status`
/// } /// }
/// ``` /// ```
pub struct PageIter<'a, T: Clone + for<'de> Deserialize<'de>> { pub struct ItemsIter<'a, T: Clone + for<'de> Deserialize<'de>> {
page: Page<'a, T>, page: Page<'a, T>,
buffer: Vec<T>, buffer: Vec<T>,
cur_idx: usize, cur_idx: usize,
use_initial: bool, use_initial: bool,
} }
impl<'a, T: Clone + for<'de> Deserialize<'de>> PageIter<'a, T> { impl<'a, T: Clone + for<'de> Deserialize<'de>> ItemsIter<'a, T> {
pub(crate) fn new(page: Page<'a, T>) -> PageIter<'a, T> { pub(crate) fn new(page: Page<'a, T>) -> ItemsIter<'a, T> {
PageIter { ItemsIter {
page: page, page: page,
buffer: vec![], buffer: vec![],
cur_idx: 0, cur_idx: 0,
@ -50,7 +50,7 @@ impl<'a, T: Clone + for<'de> Deserialize<'de>> PageIter<'a, T> {
} }
} }
impl<'a, T: Clone+ for<'de> Deserialize<'de>> Iterator for PageIter<'a, T> { impl<'a, T: Clone+ for<'de> Deserialize<'de>> Iterator for ItemsIter<'a, T> {
type Item = T; type Item = T;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {

@ -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;
pub(crate) mod pageiter; pub(crate) mod itemsiter;
pub mod relationship; pub mod relationship;
pub mod report; pub mod report;
pub mod search_result; pub mod search_result;
@ -28,7 +28,6 @@ pub mod prelude {
pub use super::list::List; pub use super::list::List;
pub use super::mention::Mention; pub use super::mention::Mention;
pub use super::notification::Notification; pub use super::notification::Notification;
pub use super::pageiter::PageIter;
pub use super::relationship::Relationship; pub use super::relationship::Relationship;
pub use super::report::Report; pub use super::report::Report;
pub use super::search_result::SearchResult; pub use super::search_result::SearchResult;

@ -3,7 +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; use entities::itemsiter::ItemsIter;
pub struct Page<'a, T: for<'de> Deserialize<'de>> { pub struct Page<'a, T: for<'de> Deserialize<'de>> {
mastodon: &'a Mastodon, mastodon: &'a Mastodon,
@ -55,8 +55,10 @@ impl<'a, T: for<'de> Deserialize<'de>> Page<'a, T> {
} }
impl<'a, T: Clone + 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> { pub fn items_iter(self) -> impl Iterator<Item = T> + 'a
PageIter::new(self) where T: 'a
{
ItemsIter::new(self)
} }
} }

Loading…
Cancel
Save