From b0ce2c21a2abc16c73fd3a80138dc299e0c59903 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 22 Jul 2019 11:10:21 +0600 Subject: [PATCH] fix state example --- examples/application/src/state.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/examples/application/src/state.rs b/examples/application/src/state.rs index 7138c39..dcffa16 100644 --- a/examples/application/src/state.rs +++ b/examples/application/src/state.rs @@ -1,6 +1,6 @@ // use actix_web::{web, App, HttpServer}; -use std::sync::{Mutex}; +use std::sync::Mutex; // This struct represents state struct AppState { @@ -8,7 +8,7 @@ struct AppState { } fn index(data: web::Data) -> String { - let app_name = data.app_name; // <- get app_name + let app_name = &data.app_name; // <- get app_name format!("Hello {}!", app_name) // <- response with app_name } @@ -29,7 +29,9 @@ fn _index(data: web::Data) -> String { // fn _main() { - let counter = web::Data::new(AppStateWithCounter { counter : Mutex::new(0)}); + let counter = web::Data::new(AppStateWithCounter { + counter: Mutex::new(0), + }); App::new() .register_data(counter.clone()) // <- register the created data @@ -42,7 +44,7 @@ pub fn main() { HttpServer::new(|| { App::new() .data(AppState { - app_name: String::from("Actix-web") + app_name: String::from("Actix-web"), }) .route("/", web::get().to(index)) })