-
Not a major issue, just a code style preference brought over from http frameworks I have used in other languages. I am wondering why I cannot move my What I'd like to do is define my app like this: #[tokio::main]
async fn main() -> std::io::Result<()> {
let mut app = App::new();
app.route("/", web::get().to(manual_hello));
app.route("/foo", web::get().to(handler_foo));
app.route("/bar", web::get().to(handler_bar));
HttpServer::new(move || app)
.bind(("127.0.0.1", 8080))?.run().await
}
async fn manual_hello() -> impl Responder {
HttpResponse::Ok().body("Hey there!")
} However it appears that |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
The closure passed to You can however return an app from a function or use |
Beta Was this translation helpful? Give feedback.
The closure passed to
HttpServer::new
is an app factory andApp
doesn't impl Clone so it's not possible to just clone the app into the re-usable closure.You can however return an app from a function or use
App::configure()
to split up or share routing setups.