the trait bound `s3::request::ResponseDataStream: tokio::io::AsyncRead` is not satisfied
frederikhors opened this issue · comments
I'm having really hard time both with 0.32 and 0.33 beta when I need to get an tokio::io::AsyncRead + Send
type in return.
I found out this extremely useful doc to convert tokio <-> futures: https://github.com/benkay86/async-applied/blob/master/reqwest-tokio-compat/src/main.rs but I cannot apply it here.
I'm using the code below:
impl Trait for Client {
async fn get_file(&self, filename: &str) -> Result<Pin<Box<dyn tokio::io::AsyncRead + Send>>> {
let file = self.bucket.get_object_stream(filename).await?;
Ok(Box::pin(file))
}
}
but it errors with:
error[E0277]: the trait bound `s3::request::ResponseDataStream: tokio::io::AsyncRead` is not satisfied
|
59 | Ok(Box::pin(file))
| ^^^^^^^^^^^^^^ the trait `tokio::io::AsyncRead` is not implemented for `s3::request::ResponseDataStream`
|
= help: the following other types implement trait `tokio::io::AsyncRead`:
&[u8]
&mut T
h2::codec::framed_write::FramedWrite<T, B>
hyper::server::tcp::addr_stream::AddrStream
hyper::upgrade::Upgraded
hyper_tls::stream::MaybeHttpsStream<T>
reqwest::async_impl::upgrade::Upgraded
sqlx_core::net::socket::Socket
and 26 others
= note: required for the cast from `s3::request::ResponseDataStream` to the object type `dyn tokio::io::AsyncRead + std::marker::Send`
Can you help me fix this, please?
Hi @frederikhors, I'd suggest using tokio::fs::file to open the file, and pass it in. Apologies for the trouble, docs have rotted a bit since 0.32, this used to be much better documented
I'm not opening a file...
I'm not opening a file...
Sorry got confused, when I saw the method name up there, get_object_stream
will return a ResponseDataStream, ResponseDataStream
in turn has the bytes method which returns a &mut Pin<Box<dyn Stream<Item = Bytes>>>
, that might get you closer to what you need
We have chosen to use other methods. Thank anyway.