From ef5b1cd37afa7617d679409c3b4a3e93ccc0887e Mon Sep 17 00:00:00 2001 From: Walther Chen Date: Wed, 22 Apr 2020 18:31:53 -0400 Subject: [PATCH] update param_with_err to param_with_reject --- src/filters/path.rs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/filters/path.rs b/src/filters/path.rs index c2b4ccfed..2c9e7f6e0 100644 --- a/src/filters/path.rs +++ b/src/filters/path.rs @@ -318,34 +318,33 @@ pub fn param( /// } /// /// impl FromStr for MyStruct { -/// type Err = MyError; +/// type Err = MyRejection; /// /// fn from_str(s: &str) -> Result { -/// let id = s.parse::().map_err(|_| MyError)?; +/// let id = s.parse::().map_err(|_| MyRejection)?; /// /// Ok(MyStruct { id }) /// } /// } /// /// #[derive(Debug)] -/// struct MyError; +/// struct MyRejection; /// -/// impl std::fmt::Display for MyError { +/// impl std::fmt::Display for MyRejection { /// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { -/// write!(f, "MyError") +/// write!(f, "My Rejection: something wrong happened.") /// } /// } /// -/// impl std::error::Error for MyError {}; -/// impl Reject for MyError {}; +/// impl Reject for MyRejection {}; /// -/// let route = warp::path::param_with_err() +/// let route = warp::path::param_with_reject() /// .map(|id: MyStruct| { /// format!("You asked for /{:?}", id) /// }) /// .recover(|err: Rejection| { /// let err = { -/// if let Some(e) = err.find::() { +/// if let Some(e) = err.find::() { /// Ok(Response::builder() /// .status(status::StatusCode::from_u16(404).unwrap()) /// .body(e.to_string()) @@ -358,20 +357,17 @@ pub fn param( /// }); /// /// ``` -pub fn param_with_err() -> impl Filter, Error = Rejection> + Copy +pub fn param_with_reject() -> impl Filter, Error = Rejection> + Copy where T: FromStr + Send + 'static, T::Err: reject::Reject, { - segment(|seg| { + filter_segment(|seg| { log::trace!("param?: {:?}", seg); if seg.is_empty() { return Err(reject::not_found()); } - T::from_str(seg).map(one).map_err(|err| { - #[allow(deprecated)] - reject::custom(err) - }) + T::from_str(seg).map(one).map_err(|err| reject::custom(err)) }) }