2019-06-20 10:20:12 +02:00
|
|
|
pub mod handlers_arc;
|
|
|
|
// <data>
|
|
|
|
use actix_web::{web, App, HttpServer, Responder};
|
2019-06-15 22:37:08 +02:00
|
|
|
use std::cell::Cell;
|
|
|
|
|
2019-06-20 10:20:12 +02:00
|
|
|
#[derive(Clone)]
|
|
|
|
struct AppState {
|
|
|
|
count: Cell<i32>,
|
|
|
|
}
|
|
|
|
|
|
|
|
fn show_count(data: web::Data<AppState>) -> impl Responder {
|
|
|
|
format!("count: {}", data.count.get())
|
|
|
|
}
|
2019-06-15 22:37:08 +02:00
|
|
|
|
2019-06-20 10:20:12 +02:00
|
|
|
fn add_one(data: web::Data<AppState>) -> impl Responder {
|
|
|
|
let count = data.count.get();
|
|
|
|
data.count.set(count + 1);
|
2019-06-15 22:37:08 +02:00
|
|
|
|
2019-06-20 10:20:12 +02:00
|
|
|
format!("count: {}", data.count.get())
|
2019-06-15 22:37:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
2019-06-20 10:20:12 +02:00
|
|
|
let data = AppState {
|
|
|
|
count: Cell::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();
|
2019-06-15 22:37:08 +02:00
|
|
|
}
|
2019-06-20 10:20:12 +02:00
|
|
|
// </data>
|