diff --git a/CHANGES.md b/CHANGES.md index a0cd0cdf9..ac94fa2f8 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,8 @@ ## 0.4.1 (2018-03-01) +* Rename `Route::p()` to `Route::filter()` + * Fix payload parse in situation when socket data is not ready. * Fix Session mutable borrow lifetime #87 diff --git a/guide/src/qs_5.md b/guide/src/qs_5.md index c1e8b615c..828a6d6c2 100644 --- a/guide/src/qs_5.md +++ b/guide/src/qs_5.md @@ -68,8 +68,8 @@ fn main() { Application::new() .resource("/path", |resource| resource.route() - .p(pred::Get()) - .p(pred::Header("content-type", "text/plain")) + .filter(pred::Get()) + .filter(pred::Header("content-type", "text/plain")) .f(|req| HTTPOk) ) .finish(); @@ -85,7 +85,7 @@ If resource can not match any route "NOT FOUND" response get returned. [*Route*](../actix_web/struct.Route.html) object. Route can be configured with builder-like pattern. Following configuration methods are available: -* [*Route::p()*](../actix_web/struct.Route.html#method.p) method registers new predicate, +* [*Route::filter()*](../actix_web/struct.Route.html#method.filter) method registers new predicate, any number of predicates could be registered for each route. * [*Route::f()*](../actix_web/struct.Route.html#method.f) method registers handler function @@ -502,7 +502,7 @@ fn main() { Application::new() .resource("/index.html", |r| r.route() - .p(ContentTypeHeader) + .filter(ContentTypeHeader) .h(HTTPOk)); } ``` @@ -530,7 +530,7 @@ fn main() { Application::new() .resource("/index.html", |r| r.route() - .p(pred::Not(pred::Get())) + .filter(pred::Not(pred::Get())) .f(|req| HTTPMethodNotAllowed)) .finish(); } @@ -568,7 +568,7 @@ fn main() { Application::new() .default_resource(|r| { r.method(Method::GET).f(|req| HTTPNotFound); - r.route().p(pred::Not(pred::Get())).f(|req| HTTPMethodNotAllowed); + r.route().filter(pred::Not(pred::Get())).f(|req| HTTPMethodNotAllowed); }) # .finish(); } diff --git a/src/pred.rs b/src/pred.rs index c84325eef..22abf6fec 100644 --- a/src/pred.rs +++ b/src/pred.rs @@ -28,7 +28,7 @@ pub trait Predicate { /// fn main() { /// Application::new() /// .resource("/index.html", |r| r.route() -/// .p(pred::Any(pred::Get()).or(pred::Post())) +/// .filter(pred::Any(pred::Get()).or(pred::Post())) /// .h(HTTPMethodNotAllowed)); /// } /// ``` @@ -71,7 +71,7 @@ impl Predicate for AnyPredicate { /// fn main() { /// Application::new() /// .resource("/index.html", |r| r.route() -/// .p(pred::All(pred::Get()) +/// .filter(pred::All(pred::Get()) /// .and(pred::Header("content-type", "plain/text"))) /// .h(HTTPMethodNotAllowed)); /// } diff --git a/src/resource.rs b/src/resource.rs index eb783a227..2e83225ea 100644 --- a/src/resource.rs +++ b/src/resource.rs @@ -81,8 +81,8 @@ impl Resource { /// let app = Application::new() /// .resource( /// "/", |r| r.route() - /// .p(pred::Any(pred::Get()).or(pred::Put())) - /// .p(pred::Header("Content-Type", "text/plain")) + /// .filter(pred::Any(pred::Get()).or(pred::Put())) + /// .filter(pred::Header("Content-Type", "text/plain")) /// .f(|r| HttpResponse::Ok())) /// .finish(); /// } @@ -97,11 +97,11 @@ impl Resource { /// This is shortcut for: /// /// ```rust,ignore - /// Resource::resource("/", |r| r.route().p(pred::Get()).f(index) + /// Resource::resource("/", |r| r.route().filter(pred::Get()).f(index) /// ``` pub fn method(&mut self, method: Method) -> &mut Route { self.routes.push(Route::default()); - self.routes.last_mut().unwrap().p(pred::Method(method)) + self.routes.last_mut().unwrap().filter(pred::Method(method)) } /// Register a new route and add handler object. diff --git a/src/route.rs b/src/route.rs index b4d1d2680..5880d669f 100644 --- a/src/route.rs +++ b/src/route.rs @@ -65,18 +65,24 @@ impl Route { /// Application::new() /// .resource("/path", |r| /// r.route() - /// .p(pred::Get()) - /// .p(pred::Header("content-type", "text/plain")) + /// .filter(pred::Get()) + /// .filter(pred::Header("content-type", "text/plain")) /// .f(|req| HTTPOk) /// ) /// # .finish(); /// # } /// ``` - pub fn p + 'static>(&mut self, p: T) -> &mut Self { + pub fn filter + 'static>(&mut self, p: T) -> &mut Self { self.preds.push(Box::new(p)); self } + #[doc(hidden)] + #[deprecated(since="0.4.1", note="please use `.filter()` instead")] + pub fn p + 'static>(&mut self, p: T) -> &mut Self { + self.filter(p) + } + /// Set handler object. Usually call to this method is last call /// during route configuration, because it does not return reference to self. pub fn h>(&mut self, handler: H) {