#Response may be Redirect or Body

1 messages · Page 1 of 1 (latest)

sage ember
#

I am trying to redirect or respond based on what page is requested, as it may not exist or not possible.

#[get("/threads/{thread_id}/page-{page}")]
async fn view_thread_page(
    req: &HttpRequest,
    path: Path<(i64, i64)>,
    context: Context,
    scylla: Data<Session>,
) -> actix_web::Result<impl Responder> {
    let (thread_id, page) = path.into_inner();

    if page > 1 {
        Ok(render_thread_page(context, scylla, thread_id, page)
            .await?
            .respond_to(req))
    } else {
        Ok(Redirect::to(format!("/threads/{}/", thread_id))
            .temporary()
            .respond_to(req))
    }
}

The compiler claims about a very difficult generic type error I'm having trouble understanding.

mismatched types
expected struct `HttpResponse<<impl Responder as Responder>::Body>`
   found struct `HttpResponse<()>`
consider constraining the associated type `<impl Responder as Responder>::Body` to `()`
for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html rustc Click for full compiler diagnostic

No matter what I've tried, I get an error similar to this. Is it possible to do what I'm attempting?

zealous edge
#

map one to _left and the other to _right