pub struct StreamingIter<'r, R> { /* private fields */ }
Expand description
An iterator-like type to “stream” records from a reader.
This API returns records which use the StreamingBody
type. This allows reading record headers
and metadata without reading the bodies. Bodies can be read or skipped as desired.
This is streaming iterator is particularly useful for streams of records which are indefinite or contain and records of unknown size.
Implementations§
Source§impl<R: BufRead> StreamingIter<'_, R>
impl<R: BufRead> StreamingIter<'_, R>
Sourcepub fn next_item(
&mut self,
) -> Option<Result<Record<StreamingBody<'_, R>>, Error>>
pub fn next_item( &mut self, ) -> Option<Result<Record<StreamingBody<'_, R>>, Error>>
Advance the stream to the next item.
Returns one of the following:
- Some(Ok(r))` is the next record read from the stream.
Some(Err)
indicates there was a read error.None
indicates no more records are returned.
Examples found in repository?
examples/read_filtered.rs (line 27)
10fn main() -> std::io::Result<()> {
11 let mut args = std::env::args_os().skip(1);
12
13 let warc_name = args
14 .next()
15 .ok_or_else(|| usage_err!("compressed warc filename not supplied"))?;
16
17 let filtered_file_names: Vec<_> = args.map(|s| s.to_string_lossy().to_string()).collect();
18 if filtered_file_names.is_empty() {
19 Err(usage_err!("one or more filtered file names not supplied"))?;
20 }
21
22 let mut file = WarcReader::from_path_gzip(warc_name)?;
23
24 let mut count = 0;
25 let mut skipped = 0;
26 let mut stream_iter = file.stream_records();
27 while let Some(record) = stream_iter.next_item() {
28 let record = record.expect("read of headers ok");
29 count += 1;
30 match record.header(WarcHeader::TargetURI).map(|s| s.to_string()) {
31 Some(v) if has_matching_filename(&v, &filtered_file_names) => {
32 println!("Matches filename, skipping record");
33 skipped += 1;
34 }
35 _ => {
36 let buffered = record.into_buffered().expect("read of record ok");
37 println!(
38 "Found record. Data:\n{}",
39 String::from_utf8_lossy(buffered.body())
40 );
41 }
42 }
43 }
44
45 println!("Total records: {}\nSkipped records: {}", count, skipped);
46
47 Ok(())
48}
Auto Trait Implementations§
impl<'r, R> Freeze for StreamingIter<'r, R>
impl<'r, R> RefUnwindSafe for StreamingIter<'r, R>where
R: RefUnwindSafe,
impl<'r, R> Send for StreamingIter<'r, R>where
R: Send,
impl<'r, R> Sync for StreamingIter<'r, R>where
R: Sync,
impl<'r, R> Unpin for StreamingIter<'r, R>
impl<'r, R> !UnwindSafe for StreamingIter<'r, R>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more