1
0
mirror of https://github.com/actix/actix-website synced 2024-11-26 01:32:42 +01:00
actix-website/examples/request-handlers/src/main.rs

26 lines
625 B
Rust
Raw Normal View History

2019-06-15 22:37:08 +02:00
mod handlers_arc;
2019-06-20 08:04:22 +02:00
// <handler>
2019-06-15 22:37:08 +02:00
use actix_web::{dev::Handler, server, App, HttpRequest, HttpResponse};
use std::cell::Cell;
struct MyHandler(Cell<usize>);
impl<S> Handler<S> for MyHandler {
type Result = HttpResponse;
/// Handle request
fn handle(&self, _req: &HttpRequest<S>) -> Self::Result {
let i = self.0.get();
self.0.set(i + 1);
HttpResponse::Ok().into()
}
}
fn main() {
server::new(|| App::new().resource("/", |r| r.h(MyHandler(Cell::new(0))))) //use r.h() to bind handler, not the r.f()
.bind("127.0.0.1:8088")
.unwrap()
.run();
}
2019-06-20 08:04:22 +02:00
// </handler>