-
I can't seem to get this working to create an use tokio::fs::File;
use tokio::io::BufReader;
use noodles_sam as sam;
let input = // command line positional argument
let mut reader = if input == "-" {
sam::AsyncReader::new(BufReader::new(tokio::io::stdin()))
} else {
File::open(input)
.await
.map(BufReader::new)
.map(sam::AsyncReader::new)?
}; this give the error
This code was essentially the same for the sync version (and compiled fine), I just changed the use to tokio and AsyncReader. In addition, to save me going down a deadend, I am converting this codebase from sync to async. The important part is that I want to be able to gather some information about records as they come in and every
but is this just because I am not currently using the AsyncReader. Will this all go away when I successfully get the AsyncReader working? Or will this still be impossible with the AsyncReader? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
All branches of an let reader: Box<dyn AsyncBufRead + Unpin> = if src == "-" {
Box::new(BufReader::new(io::stdin()))
} else {
File::open(src).await.map(BufReader::new).map(Box::new)?
};
let mut reader = sam::r#async::io::Reader::new(reader);
// => sam::r#async::io::Reader<Box<dyn AsyncBufRead + Unpin>>
If let record = reader.records().try_next().await?.expect("missing record");
let record: Box<dyn sam::alignment::Record + Send> = Box::new(record);
sender.send(SenderEvent::Record(record)).await?; |
Beta Was this translation helpful? Give feedback.
All branches of an
if
expression must return the same type. This is hinted by the error message "if
andelse
have incompatible types", i.e., the inner readerstokio::io::Stdin
andtokio::fs::File
are of two different types. Given both readers implementAsyncBufRead
, you can cast them to boxed trait objects to return a homogeneous type. (Most tokio I/O extension operations do not assume the reader is address-sensitive, so we also requireUnpin
.)