I have a variable that will control which function is the default behavior of my web app, but both functions are async
and it wont let me because they're different closures. Something like this reproduces the same error:
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=db0269ef4852a94438e6d4925ca83d3b
Now my questions are:
- How do I solve this so that the match works?
- Is there a better way to set default server behavior programatically on actix based on user CLI flags? For context, this is more or less what I have:
main.rs
// Matches comes from the command line
let a = match matches.occurrences_of("default"){
1 => handlers::forward,
_ => handlers::resource_not_found,
};
... setting up db, auth etc
HttpServer::new(move || {
App::new()
... lots of routes
.default_service(web::route().to(a))
handlers.rs
pub async fn resource_not_found(
) -> Result<HttpResponse, Error> {
Ok(HttpResponse::NotFound().body("Resource does not exist"))
}
pub async fn forward(
) -> Result<HttpResponse, Error> {
Ok(HttpResponse::Ok().body("Resource does exist"))
}