1
0
mirror of https://github.com/actix/actix-extras.git synced 2025-06-26 10:27:42 +02:00

rename .p to a .filter

This commit is contained in:
Nikolay Kim
2018-03-01 18:32:31 -08:00
parent 5b6d7cddbf
commit 4e13505b92
5 changed files with 23 additions and 15 deletions

View File

@ -28,7 +28,7 @@ pub trait Predicate<S> {
/// 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<S: 'static> Predicate<S> for AnyPredicate<S> {
/// 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));
/// }

View File

@ -81,8 +81,8 @@ impl<S: 'static> Resource<S> {
/// 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<S: 'static> Resource<S> {
/// 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<S> {
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.

View File

@ -65,18 +65,24 @@ impl<S: 'static> Route<S> {
/// 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<T: Predicate<S> + 'static>(&mut self, p: T) -> &mut Self {
pub fn filter<T: Predicate<S> + '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<T: Predicate<S> + '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<H: Handler<S>>(&mut self, handler: H) {