// use actix_web::{web, Responder}; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; #[derive(Clone)] struct AppState { count: Arc, } async fn show_count(data: web::Data) -> impl Responder { format!("count: {}", data.count.load(Ordering::Relaxed)) } async fn add_one(data: web::Data) -> impl Responder { data.count.fetch_add(1, Ordering::Relaxed); format!("count: {}", data.count.load(Ordering::Relaxed)) } #[actix_rt::main] async fn main() -> std::io::Result<()> { use actix_web::{App, HttpServer}; let data = AppState { count: Arc::new(AtomicUsize::new(0)), }; HttpServer::new(move || { App::new() .app_data(data.clone()) .route("/", web::to(show_count)) .route("/add", web::to(add_one)) }) .bind("127.0.0.1:8088")? .run() .await } //