I have some actix_web stuff wrapped in a module and pulled in by my REST api functions, except for too much kick-starting boilerplate:
#[actix_web::main]
async fn main() -> std::io::Result<()> {
HttpServer::new(|| App::new()
.wrap(Logger::default())
.service((api1, api2, api3)))
.bind(("127.0.0.1", 8081))?
.run()
.await
}
I'd like to get the low-level parts out of sight and have only the business logic stuff (bind-address & rest-apis) visible. I.e. simplify main()
to one of:
web::init((api1, api2, api3))
.bind(("127.0.0.1", 8081))?
.run()
.await
web::init(|app| app.service((api1, api2, api3)))
.bind(("127.0.0.1", 8081))?
.run()
.await
web::run(("127.0.0.1", 8081), (api1, api2, api3))?
But just refactoring this into a separate function changes everything. Whatever I try, I always stumble across many suddenly needed generic parameters, moving the tuple into the closure is suddenly considered to cross thread boundaries, etc. How to write such an init
or run
function?