From f43a46b58e2768ab1bf1dc505a1d6d68f204f8f5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Sta=C5=A1?= Date: Wed, 25 Sep 2019 06:37:36 +0200 Subject: [PATCH] Make sure app_mutable example works out of box (#112) The page which refers make_app_mutable section: https://actix.rs/docs/application/ Although the original example compiled, I found it a bit incomplete as it didn't really start the server. As a beginner, I first tried to reuse original `main()` example and ran into lifetime issue with counter instance. Took me a bit to figure "ahha sure, I need to move it in." --- examples/application/src/state.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/application/src/state.rs b/examples/application/src/state.rs index dcffa16..c2a7abd 100644 --- a/examples/application/src/state.rs +++ b/examples/application/src/state.rs @@ -33,9 +33,15 @@ fn _main() { counter: Mutex::new(0), }); - App::new() - .register_data(counter.clone()) // <- register the created data - .route("/", web::get().to(index)); + HttpServer::new(move || { // move counter into the closure + App::new() + .register_data(counter.clone()) // <- register the created data + .route("/", web::get().to(_index)) + }) + .bind("127.0.0.1:8088") + .unwrap() + .run() + .unwrap(); } //