perf_event_open/sample/auxiliary/iter/
mod.rs

1use std::io::Result;
2use std::num::NonZeroUsize;
3
4mod cow;
5
6pub use cow::*;
7
8/// AUX area iterator.
9pub struct Iter<'a>(pub(super) CowIter<'a>);
10
11impl<'a> Iter<'a> {
12    /// Advances the iterator and returns the next value.
13    ///
14    /// `max_chunk_len` specifies the maximum length of a chunk
15    /// that can be produced at one time, unlimited if `None`.
16    pub fn next(&mut self, max_chunk_len: Option<NonZeroUsize>) -> Option<Vec<u8>> {
17        self.0.next(|cc| cc.into_owned(), max_chunk_len)
18    }
19
20    /// Returns the underlying COW iterator.
21    pub fn into_cow(self) -> CowIter<'a> {
22        self.0
23    }
24
25    /// Creates an asynchronous iterator.
26    pub fn into_async(self) -> Result<AsyncIter<'a>> {
27        Ok(AsyncIter(self.0.into_async()?))
28    }
29}
30
31/// Asynchronous AUX area iterator.
32pub struct AsyncIter<'a>(AsyncCowIter<'a>);
33
34impl AsyncIter<'_> {
35    /// Advances the iterator and returns the next value.
36    ///
37    /// `max_chunk_len` specifies the maximum length of a chunk
38    /// that can be produced at one time, unlimited if `None`.
39    pub async fn next(&mut self, max_chunk_len: Option<NonZeroUsize>) -> Option<Vec<u8>> {
40        self.0.next(|cc| cc.into_owned(), max_chunk_len).await
41    }
42}