0

I am using the following actix handler:

fn callback(info: web::Query<CallbackInfo>, session: Session) -> impl Future<Item = HttpResponse, Error = actix_web::Error>

Inside this function I do some branching and sometimes I return:

web::block(|| Result::<Backup, String>::Ok(run_backup(token_info)))
    .from_err()
    .map(|backup| HttpResponse::Ok().json(backup))

other times I return:

let r = HttpResponse::Found()
    .set_header(http::header::LOCATION, "/")
    .finish();
futures::future::ok(r)

Which fails to compile with

expected struct `futures::future::map::Map`, found struct `futures::future::result_::FutureResult`

Which I think I understand, even though it's weird that .map doesn't return another future. But how can I unify these two times so I can use them as return types?

Update: It has been suggested this is a duplicate of: Why can impl trait not be used to return multiple / conditional types? But that question does not solve this problem, it only describes why this occurs. I see that the problem is with impl Future, but I cannot change this as I am using actix-web, which requires this signature, or a similar signature that I am not able to find out, hence why I ask this question.

Ömer Erden
  • 7,680
  • 5
  • 36
  • 45
simao
  • 14,491
  • 9
  • 55
  • 66
  • Does this answer your question? [Why can impl trait not be used to return multiple / conditional types?](https://stackoverflow.com/questions/52001592/why-can-impl-trait-not-be-used-to-return-multiple-conditional-types) – Stargateur Nov 24 '19 at 17:50
  • No, not really. impl Future is imposed on me by actix? – simao Nov 24 '19 at 18:23
  • The actix-web book [handlers chapter](https://actix.rs/docs/handlers/) *Different return types (Either)* section might be of help for you. But without a [minimal reproducible example](https://stackoverflow.com/help/minimal-reproducible-example), one can never be certain. – edwardw Nov 25 '19 at 05:23
  • to be honest this is a bad question so downvoting is here to says this is a bad question. The duplicate is perfect, if you can't change your return type so the answer of shepmaster is for you. – Stargateur Nov 25 '19 at 10:48
  • Can you explain how this is a bad question? – simao Nov 25 '19 at 11:38
  • @edwardw Yeah that works, thanks a lot I didn't see that in the docs. – simao Nov 25 '19 at 12:06

0 Answers0