Migrate to Axum 0.7

I have following handler:

// data_stream is https://docs.rs/rust-s3/latest/s3/request/request_trait/struct.ResponseDataStream.html
async fn find_stream() -> Response {
    match s3::get_stream().await {
        Ok(data_stream) => {
            let body = StreamBody::from(data_stream.bytes);
            let response = Response::builder()
                .header("Content-Type", object_type)
                .body(body)
                .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR.into_response());
            response.into_response()
        }
        Err(_) => StatusCode::NOT_FOUND.into_response(),
    }
}

Now changed Streambody with http-body-util's version:

...
let body = StreamBody::new(data_stream.bytes);
...

But now getting error:

error[E0599]: the method `into_response` exists for enum `Result<Response<StreamBody<Pin<Box<dyn Stream<Item = Result<Bytes, S3Error>> + Send>>>>, Response<Body>>`, but its trait bounds were not satisfied
   --> src/routes.rs:566:22
    |
566 |             response.into_response()
    |                      ^^^^^^^^^^^^^ method cannot be called due to unsatisfied trait bounds

What can I do?

Try using the debug handler macro (debug_handler in axum_macros - Rust) in order to get a more actionable error.

Why you don't use Body in axum::body - Rust?

It should also be possible to use Response::new(body) directly instead of the not implemented IntoResponse trait. Response is from http crate in both axum and http_body_util crate.
But not sure why you want to use StreamBody from it.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.