memory_pager/
iter.rs

1use super::{Page, Pager};
2use std::{iter, slice};
3
4/// Iterator over a `Pager` instance.
5///
6/// ```rust
7/// # extern crate memory_pager;
8/// # use memory_pager::Pager;
9/// let mut pager = Pager::default();
10/// pager.get_mut_or_alloc(1);
11/// pager.get_mut_or_alloc(2);
12/// pager.get_mut_or_alloc(3);
13///
14/// for page in pager.iter() {
15///   println!("page {:?}", page);
16/// }
17/// ```
18pub struct Iter<'a> {
19  inner: slice::Iter<'a, Option<Page>>,
20}
21
22impl<'a> Iter<'a> {
23  #[inline]
24  pub(crate) fn new(pager: &'a Pager) -> Self {
25    Self {
26      inner: pager.pages.iter(),
27    }
28  }
29}
30
31impl<'a> iter::Iterator for Iter<'a> {
32  type Item = &'a Option<Page>;
33
34  fn next(&mut self) -> Option<Self::Item> {
35    self.inner.next()
36  }
37}