Available on
unstable_lending_iterators
only.Expand description
Traits and implementations for lending iterators for hunks and metadata.
These APIs should be considered unstable and will be replaced with APIs
based around GATs and LendingIterator
once stabilized. See rust#44265
for the tracking issue on GAT stabilization.
§Iterating over hunks with LendingIterator
LendingIterator
allows a more ergonomic interface to iterate over hunks.
use std::fs::File;
use std::io::BufReader;
use lending_iterator::LendingIterator;
use chd::Chd;
let mut f = BufReader::new(File::open("file.chd")?);
let mut chd = Chd::open(&mut f, None)?;
// buffer to store uncompressed hunk data must be the same length as the hunk size.
let mut hunk_buf = chd.get_hunksized_buffer();
// buffer to store compressed data.
let mut cmp_buf = Vec::new();
let mut hunks = chd.hunks();
while let Some(mut hunk) = hunks.next() {
hunk.read_hunk_in(&mut cmp_buf, &mut hunk_buf)?;
}
§Iterating over metadata with LendingIterator
LendingIterator allows iterating over metadata without keeping a reference to the source file.
use std::fs::File;
use std::io::BufReader;
use lending_iterator::LendingIterator;
use chd::Chd;
let mut f = BufReader::new(File::open("file.chd")?);
let mut chd = Chd::open(&mut f, None)?;
let mut metadata = chd.metadata();
while let Some(mut metadata) = metadata.next() {
let metadata = metadata.read()?;
}
Structs§
- An iterator over the hunks of a CHD file.
- An iterator over the metadata entries of a CHD file.
- A metadata entry for a CHD file that has a reference to the source file, allowing read metadata from the stream without an explicit reference.
Traits§
- A
LendingIterator
definition re-exported from the lending-iterator crate. Provides an lending iterator interface with various adapters that map to those fromIterator
.