add page num counting to ItemsIter

master
Ondřej Hruška 3 years ago
parent 51e52bc24b
commit b10e5935ae
Signed by: MightyPork
GPG Key ID: 2C5FD5035250423D
  1. 7
      src/entities/itemsiter.rs

@ -7,6 +7,7 @@ pub struct ItemsIter<'a, T: Clone + for<'de> Deserialize<'de>> {
page: Page<'a, T>,
buffer: Vec<T>,
cur_idx: usize,
cur_page: usize,
use_initial: bool,
}
@ -16,6 +17,7 @@ impl<'a, T: Clone + for<'de> Deserialize<'de>> ItemsIter<'a, T> {
page,
buffer: vec![],
cur_idx: 0,
cur_page: 0,
use_initial: true,
}
}
@ -36,12 +38,17 @@ impl<'a, T: Clone + for<'de> Deserialize<'de>> ItemsIter<'a, T> {
}
self.buffer = items;
self.cur_idx = 0;
self.cur_page += 1;
Some(())
} else {
None
}
}
pub fn page_num(&self) -> usize {
self.cur_page
}
pub async fn next_item(&mut self) -> Option<T> {
if self.use_initial {
if self.page.initial_items.is_empty() || self.cur_idx == self.page.initial_items.len() {

Loading…
Cancel
Save