perf_event_open/sample/iter/
mod.rs

1use std::io::Result;
2
3use super::record::{Priv, Record};
4
5mod cow;
6
7pub use cow::*;
8
9/// Record iterator.
10pub struct Iter<'a>(pub(super) CowIter<'a>);
11
12impl<'a> Iter<'a> {
13    /// Returns the underlying COW iterator.
14    pub fn into_cow(self) -> CowIter<'a> {
15        self.0
16    }
17
18    /// Creates an asynchronous iterator.
19    pub fn into_async(self) -> Result<AsyncIter<'a>> {
20        Ok(AsyncIter(self.0.into_async()?))
21    }
22}
23
24impl Iterator for Iter<'_> {
25    type Item = (Priv, Record);
26
27    fn next(&mut self) -> Option<Self::Item> {
28        self.0.next(|cc, p| p.parse(cc))
29    }
30}
31
32/// Asynchronous record iterator.
33pub struct AsyncIter<'a>(AsyncCowIter<'a>);
34
35impl AsyncIter<'_> {
36    /// Advances the iterator and returns the next value.
37    ///
38    /// [`WakeUpOn`][crate::config::WakeUpOn] must be properly set to make this work.
39    pub async fn next(&mut self) -> Option<(Priv, Record)> {
40        self.0.next(|cc, p| p.parse(cc)).await
41    }
42}