My Rust program should either read from stdin or from a file stored on S3. Currently I have something like this:
fn load_from_s3(url: &String) -> impl Read {
// ...
BufReader::new(some_stream)
}
// ...
let reader = match cli.value_of("s3_url") {
Some(url) => csv::Reader::from_reader(load_from_s3(&url.to_string())),
None => {
let lock = io::stdin().lock();
csv::Reader::from_reader(lock)
}
};
The Some
branch warns me about this is found to be of type csv::reader::Reader<impl std::io::Read>
. The None
branch gives me the error expected opaque type, found struct std::io::StdinLock
. I'm rather new to Rust and cannot figure out, how to get the types right.