zaeleus / noodles

Bioinformatics I/O libraries in Rust
MIT License
512 stars 53 forks source link

`gff::AsyncReader` gated by async feature #264

Closed tshauck closed 6 months ago

tshauck commented 6 months ago

Thanks for the quick update w.r.t. the async reader. I tried to give it shot, but am running into an issue where AsyncReader is seemingly gated by the async feature even though it's enabled and seems to work for other subcrates (e.g. fasta).

To reproduce, you can create a new crate with a file that like:

//! Counts the number of records in a GFF file.
//!
//! Assuming the input does not have a FASTA section, the result matches the output of `grep
//! --count --invert-match '^#' <src>`.

use std::env;

use futures::TryStreamExt;
use tokio::{
    fs::File,
    io::{self, BufReader},
};

#[tokio::main]
async fn main() -> io::Result<()> {
    let src = env::args().nth(1).expect("missing src");

    let mut reader = File::open(src)
        .await
        .map(BufReader::new)
        .map(noodles::gff::AsyncReader::new)?;

    let mut records = reader.records();
    let mut n = 0;

    while records.try_next().await?.is_some() {
        n += 1;
    }

    println!("{n}");

    let mut reader = File::open(src)
        .await
        .map(BufReader::new)
        .map(noodles::fasta::AsyncReader::new)?;

    Ok(())
}

And a cargo.toml that looks like:

[package]
name = "gff-async-test"
version = "0.1.0"
edition = "2021"

[dependencies]
futures = { version = "0.3.30", features = ["std"] }
noodles = { version = "0.73.0", features = ["gff", "async", "fasta"] }
tokio = { version = "1.37.0", features = ["full"] }

With the above code, I get the error that...

error[E0433]: failed to resolve: could not find `AsyncReader` in `gff`
  --> src/main.rs:21:28
   |
21 |         .map(noodles::gff::AsyncReader::new)?;
   |                            ^^^^^^^^^^^ could not find `AsyncReader` in `gff`
   |
note: found an item that was configured out
  --> /Users/thauck/.cargo/registry/src/index.crates.io-6f17d22bba15001f/noodles-gff-0.32.0/src/lib.rs:47:34
   |
47 | pub use self::r#async::Reader as AsyncReader;
   |                                  ^^^^^^^^^^^
   = note: the item is gated behind the `async` feature

Note that near the end of the file I have fasta::AsyncReader and that seems to compile fine.

zaeleus commented 6 months ago

Ah, the feature wasn't added to the noodles meta-crate.

A workaround in the interim is to add noodles-gff with the async feature enabled to your list of dependencies, i.e.,

noodles-gff = { version = "0.32.0", features = ["async"] }
tshauck commented 6 months ago

Thanks!