Skip to main content

FastqChunkSinkExt

Trait FastqChunkSinkExt 

Source
pub trait FastqChunkSinkExt: FastqRecordSink {
    // Provided method
    fn reserve_records(&mut self, _records: usize) { ... }
}
Expand description

Optional extension point for sinks that can preallocate per chunk.

Dino Seq calls FastqRecordSink::record for correctness. Downstream tools that own a growable output buffer can also implement this trait locally and call FastqChunkConfig::estimated_records before invoking FastqReader::next_chunk_with_sink.

Provided Methods§

Source

fn reserve_records(&mut self, _records: usize)

Reserve space for approximately records upcoming records.

Examples found in repository?
examples/fastq_chunk_sink.rs (line 51)
45fn main() -> Result<()> {
46    let stdin = io::stdin();
47    let mut reader = FastqReader::new(stdin.lock());
48    let config = FastqChunkConfig::new(10_000_000).min_records(40_000);
49    let mut sink = ReadBuffer::default();
50
51    sink.reserve_records(config.estimated_records(150));
52    while let Some(stats) = reader.next_chunk_with_sink(config, &mut sink)? {
53        let checksum: usize = sink
54            .reads
55            .iter()
56            .map(|read| read.name.len() ^ read.seq.len() ^ read.qual.len())
57            .sum();
58        eprintln!(
59            "chunk first_record={} records={} bases={} checksum={}",
60            stats.first_record_index(),
61            stats.records(),
62            stats.bases(),
63            checksum
64        );
65
66        // Downstream tools typically hand `sink.reads` to alignment or another
67        // processing stage here, then reuse the allocation for the next chunk.
68        sink.clear();
69        sink.reserve_records(config.estimated_records(150));
70    }
71
72    Ok(())
73}

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§