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