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.