diff --git a/src/filters/path.rs b/src/filters/path.rs index ed98b9e80..c2b4ccfed 100644 --- a/src/filters/path.rs +++ b/src/filters/path.rs @@ -282,10 +282,13 @@ pub fn param( /// /// If the value could not be parsed, rejects with a custom [`Rejection`][]. /// +/// You'll need to implement [`reject::Reject`][] as a marker trait. +/// /// Since [`warp::reject::custom`][] is used to create a `Rejection` under the hood, /// a [`recover`][] filter should convert this `Rejection` into a `Reply`, or else /// this will be returned as a `500 Internal Server Error`. /// +/// [`reject::Reject`]: ../../reject/trait.Reject.html /// [`Rejection`]: ../../reject/struct.Rejection.html /// [`recover`]: ../trait.Filter.html#method.recover /// [`warp::reject::custom`]: ../../reject/fn.custom.html @@ -302,8 +305,11 @@ pub fn param( /// status, /// Response, /// }, +/// reject::{ +/// Reject, +/// Rejection, +/// }, /// Filter, -/// Rejection /// }; /// /// #[derive(Debug)] @@ -331,6 +337,7 @@ pub fn param( /// } /// /// impl std::error::Error for MyError {}; +/// impl Reject for MyError {}; /// /// let route = warp::path::param_with_err() /// .map(|id: MyStruct| { @@ -338,7 +345,7 @@ pub fn param( /// }) /// .recover(|err: Rejection| { /// let err = { -/// if let Some(e) = err.find_cause::() { +/// if let Some(e) = err.find::() { /// Ok(Response::builder() /// .status(status::StatusCode::from_u16(404).unwrap()) /// .body(e.to_string()) @@ -354,7 +361,7 @@ pub fn param( pub fn param_with_err() -> impl Filter, Error = Rejection> + Copy where T: FromStr + Send + 'static, - T::Err: Into, + T::Err: reject::Reject, { segment(|seg| { log::trace!("param?: {:?}", seg); @@ -363,7 +370,7 @@ where } T::from_str(seg).map(one).map_err(|err| { #[allow(deprecated)] - reject::custom(err.into()) + reject::custom(err) }) }) }