From 997fb14e79ab22a90980150f230875c41f083d89 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 26 Feb 2022 04:50:39 +0000 Subject: [PATCH] fix note about app_data --- content/docs/whatis.md | 4 ++-- examples/application/src/mutable_state.rs | 4 ++-- examples/application/src/state.rs | 3 +-- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/content/docs/whatis.md b/content/docs/whatis.md index 49b0865..b2dfe9c 100644 --- a/content/docs/whatis.md +++ b/content/docs/whatis.md @@ -1,10 +1,10 @@ --- -title: What is Actix +title: What is Actix Web menu: docs_intro weight: 100 --- -# Actix is an Ecosystem of Crates +# Actix Web is part of an Ecosystem of Crates Long ago, Actix Web was built on top of the `actix` actor framework. Now, Actix Web is largely unrelated to the actor framework and is built using a different system. Though `actix` is still maintained, its usefulness as a general tool is diminishing as the futures and async/await ecosystem matures. At this time, the use of `actix` is only required for WebSocket endpoints. diff --git a/examples/application/src/mutable_state.rs b/examples/application/src/mutable_state.rs index c326937..39254c6 100644 --- a/examples/application/src/mutable_state.rs +++ b/examples/application/src/mutable_state.rs @@ -10,13 +10,14 @@ async fn index(data: web::Data) -> String { let mut counter = data.counter.lock().unwrap(); // <- get counter's MutexGuard *counter += 1; // <- access counter inside MutexGuard - format!("Request number: {}", counter) // <- response with count + format!("Request number: {counter}") // <- response with count } // // #[actix_web::main] async fn main() -> std::io::Result<()> { + // Note: web::Data created _outside_ HttpServer::new closure let counter = web::Data::new(AppStateWithCounter { counter: Mutex::new(0), }); @@ -24,7 +25,6 @@ async fn main() -> std::io::Result<()> { HttpServer::new(move || { // move counter into the closure App::new() - // Note: using app_data instead of data .app_data(counter.clone()) // <- register the created data .route("/", web::get().to(index)) }) diff --git a/examples/application/src/state.rs b/examples/application/src/state.rs index 72c7e03..f45399b 100644 --- a/examples/application/src/state.rs +++ b/examples/application/src/state.rs @@ -9,8 +9,7 @@ struct AppState { #[get("/")] async fn index(data: web::Data) -> String { let app_name = &data.app_name; // <- get app_name - - format!("Hello {}!", app_name) // <- response with app_name + format!("Hello {app_name}!") // <- response with app_name } //