mirror of
https://github.com/actix/actix-website
synced 2025-01-22 16:15:56 +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:
parent
29d1d51cf1
commit
f43a46b58e
@ -33,9 +33,15 @@ fn _main() {
|
||||
counter: Mutex::new(0),
|
||||
});
|
||||
|
||||
HttpServer::new(move || { // move counter into the closure
|
||||
App::new()
|
||||
.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>
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user