Skip to main content

proc_status/
entries.rs

1use {
2    crate::*,
3    std::{
4        str::Split,
5    },
6};
7
8/// an iterator over the entries of a procstatus.
9///
10/// You get it from the proc status instance.
11pub struct ProcEntries<'p> {
12    split: Split<'p, char>,
13}
14
15impl<'p> ProcEntries<'p> {
16    pub(crate) fn from_content(content: &'p str) -> Self {
17        let split = content.split('\n');
18        Self { split }
19    }
20}
21
22impl<'p> Iterator for ProcEntries<'p> {
23    type Item = Result<ProcEntry<'p>, ProcStatusError>;
24    fn next(&mut self) -> Option<Result<ProcEntry<'p>, ProcStatusError>> {
25        loop {
26            match self.split.next() {
27                None => { return None; }
28                Some(s) => {
29                    if !s.is_empty() { return Some(ProcEntry::new(s)); }
30                }
31            }
32        }
33    }
34}