mod builder;
use std::pin::Pin;
use futures::{Stream, StreamExt};
use noodles_bcf as bcf;
use noodles_vcf as vcf;
use tokio::io::{self, AsyncBufRead};
pub use self::builder::Builder;
pub enum Reader<R> {
Bcf(bcf::r#async::io::Reader<R>),
Vcf(vcf::r#async::io::Reader<R>),
}
impl<R> Reader<R>
where
R: AsyncBufRead + Unpin,
{
pub async fn read_header(&mut self) -> io::Result<vcf::Header> {
match self {
Self::Bcf(reader) => reader.read_header().await,
Self::Vcf(reader) => reader.read_header().await,
}
}
pub fn records(
&mut self,
) -> impl Stream<Item = io::Result<Box<dyn vcf::variant::Record>>> + '_ {
#[allow(clippy::type_complexity)]
let records: Pin<
Box<dyn Stream<Item = io::Result<Box<dyn vcf::variant::Record>>>>,
> = match self {
Reader::Bcf(reader) => Box::pin(reader.records().map(|result| {
result.map(|record| Box::new(record) as Box<dyn vcf::variant::Record>)
})),
Reader::Vcf(reader) => Box::pin(reader.records().map(|result| {
result.map(|record| Box::new(record) as Box<dyn vcf::variant::Record>)
})),
};
records
}
}