struct_handler/
struct_handler.rs1extern crate iron;
2extern crate router;
3
4use iron::Handler;
5use iron::status;
6use iron::IronResult;
7use iron::Response;
8use iron::Request;
9use iron::Iron;
10use router::Router;
11
12struct MessageHandler {
13 message: String
14}
15
16impl Handler for MessageHandler {
17 fn handle(&self, _: &mut Request) -> IronResult<Response> {
18 Ok(Response::with((status::Ok, self.message.clone())))
19 }
20}
21
22fn main() {
23 let handler = MessageHandler {
24 message: "You've found the index page!".to_string()
25 };
26
27 let mut router = Router::new();
28 router.get("/", handler, "index");
29
30 Iron::new(router).http("localhost:3000").unwrap();
31}