Skip to content

Commit

Permalink
util/variant/io/indexed_reader: Change IndexedReader::records to retu…
Browse files Browse the repository at this point in the history
…rn an iterator over vcf::variant::Record trait objects
  • Loading branch information
zaeleus committed Mar 26, 2024
1 parent 62e475c commit 71ab108
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
5 changes: 3 additions & 2 deletions noodles-util/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
* util/variant: Move readers (`Reader` and `IndexedReader`) and writer
(`Writer`) to `io` module.

* util/variant/io/indexed_reader: Changed `IndexedReader::query` to return an
iterator over `io::Result<Box<dyn vcf::variant::Record>>`.
* util/variant/io/indexed_reader: Change iterators (`IndexedReader::records`
and IndexedReader::query`) to return an iterator over
`vcf::variant::Record` trait objects.

* util/variant/io/reader: Change `Reader::records` to return an iterator
over `vcf::variant::Record` trait objects.
Expand Down
22 changes: 13 additions & 9 deletions noodles-util/src/variant/io/indexed_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ use std::io::{self, Read, Seek};
use noodles_bcf as bcf;
use noodles_bgzf as bgzf;
use noodles_core::Region;
use noodles_vcf::{
self as vcf,
variant::{Record, RecordBuf},
};
use noodles_vcf::{self as vcf, variant::Record};

/// An indexed variant reader.
pub enum IndexedReader<R> {
Expand All @@ -37,11 +34,18 @@ where
/// Returns an iterator over records starting from the current stream position.
pub fn records<'r, 'h: 'r>(
&'r mut self,
header: &'h vcf::Header,
) -> impl Iterator<Item = io::Result<RecordBuf>> + '_ {
let records: Box<dyn Iterator<Item = io::Result<RecordBuf>>> = match self {
Self::Vcf(reader) => Box::new(reader.record_bufs(header)),
Self::Bcf(reader) => Box::new(reader.record_bufs(header)),
) -> impl Iterator<Item = io::Result<Box<dyn Record>>> + '_ {
let records: Box<dyn Iterator<Item = io::Result<Box<dyn Record>>>> = match self {
Self::Vcf(reader) => Box::new(
reader
.records()
.map(|result| result.map(|record| Box::new(record) as Box<dyn Record>)),
),
Self::Bcf(reader) => Box::new(
reader
.records()
.map(|result| result.map(|record| Box::new(record) as Box<dyn Record>)),
),
};

records
Expand Down

0 comments on commit 71ab108

Please sign in to comment.