1
0
mirror of https://github.com/actix/actix-website synced 2025-01-23 00:25:55 +01:00

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."
This commit is contained in:
Patrik Staš 2019-09-25 06:37:36 +02:00 committed by Nikolay Kim
parent 29d1d51cf1
commit f43a46b58e

View File

@ -33,9 +33,15 @@ fn _main() {
counter: Mutex::new(0), counter: Mutex::new(0),
}); });
HttpServer::new(move || { // move counter into the closure
App::new() App::new()
.register_data(counter.clone()) // <- register the created data .register_data(counter.clone()) // <- register the created data
.route("/", web::get().to(index)); .route("/", web::get().to(_index))
})
.bind("127.0.0.1:8088")
.unwrap()
.run()
.unwrap();
} }
// </make_app_mutable> // </make_app_mutable>