From fd6b243cd6d1b3a0896daf988897b982447acd11 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Mon, 4 Dec 2017 16:32:31 -0800 Subject: [PATCH] update examples --- examples/tls/src/main.rs | 4 ++-- examples/websocket-chat/src/main.rs | 6 +++--- src/route.rs | 12 ++++++------ 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/examples/tls/src/main.rs b/examples/tls/src/main.rs index 81574e5e5..3368c4ebc 100644 --- a/examples/tls/src/main.rs +++ b/examples/tls/src/main.rs @@ -34,9 +34,9 @@ fn main() { // enable logger .middleware(middlewares::Logger::default()) // register simple handler, handle all methods - .handler("/index.html", index) + .route("/index.html", |r| r.f(index)) // with path parameters - .resource("/", |r| r.handler(Method::GET, |req| { + .resource("/", |r| r.method(Method::GET).f(|req| { httpcodes::HTTPFound .build() .header("LOCATION", "/index.html") diff --git a/examples/websocket-chat/src/main.rs b/examples/websocket-chat/src/main.rs index 8a83e35dc..797d4690c 100644 --- a/examples/websocket-chat/src/main.rs +++ b/examples/websocket-chat/src/main.rs @@ -199,16 +199,16 @@ fn main() { HttpServer::new( Application::build("/", state) // redirect to websocket.html - .resource("/", |r| r.handler(Method::GET, |req| { + .resource("/", |r| r.method(Method::GET).f(|req| { httpcodes::HTTPFound .build() .header("LOCATION", "/static/websocket.html") .body(Body::Empty) })) // websocket - .resource("/ws/", |r| r.get(chat_route)) + .resource("/ws/", |r| r.route().f(chat_route)) // static resources - .route("/static", fs::StaticFiles::new("static/", true))) + .route("/static", |r| r.h(fs::StaticFiles::new("static/", true)))) .serve::<_, ()>("127.0.0.1:8080").unwrap(); let _ = sys.run(); diff --git a/src/route.rs b/src/route.rs index 7739ff71b..64f037d8d 100644 --- a/src/route.rs +++ b/src/route.rs @@ -43,9 +43,9 @@ impl Route { self.handler.handle(req) } - /// Add match predicate to route. - pub fn p(&mut self, p: Box>) -> &mut Self { - self.preds.push(p); + /// Add method check to route. This method could be called multiple times. + pub fn method(&mut self, method: Method) -> &mut Self { + self.preds.push(pred::Method(method)); self } @@ -57,9 +57,9 @@ impl Route { self } - /// Add method check to route. This method could be called multiple times. - pub fn method(&mut self, method: Method) -> &mut Self { - self.preds.push(pred::Method(method)); + /// Add match predicate to route. + pub fn p(&mut self, p: Box>) -> &mut Self { + self.preds.push(p); self }