I'm new to rust, so, perhaps there's a way to do this that i'm not aware of, but, if I convert a reqwest::Body
into a stream and invoke, for example, try_for_each_concurrent
, the stream's Error type is reqwest::Error
, so, I'm expected to return something of that type in the closure.
But it is not possible, outside of the reqwest crate itself, to construct a reqwest::Error
.
For example:
let mut stream = reqwest::get("http://httpbin.org/ip")
.await?
.bytes_stream();
let result = stream.try_for_each_concurrent(2, |c| async move {
// This cannot work:
let transformed = some_function_that_can_return_another_kind_of_error(c)?;
// And there's no way to convert into a `reqwest::Error`, AFAIK
});
Since the types are out of my control, an alternative idea I had is to create a stream that consumes the stream from reqwest, but can't seem to find a simple way to do that. Is there a correct/idiomatic way of handling situations like this I'm not aware of?
Thanks for the help!