use "map_err()" and "?" instead of "match {}"
@@ -9,16 +9,8 @@ async fn add_one(cx: Request<()>) -> Result<String, tide::Error> {
}
async fn add_two(cx: Request<()>) -> Result<String, tide::Error> {
- let one;
- match cx.param::<i64>("one") {
- Ok(num) => one = num,
- Err(err) => return Err(tide::Error::new(StatusCode::BadRequest, err)),
- };
- let two;
- match cx.param::<i64>("two") {
- Ok(num) => two = num,
- Err(err) => return Err(tide::Error::new(StatusCode::BadRequest, err)),
- };
+ let one= cx.param::<i64>("one").map_err(|err| tide::Error::new(StatusCode::BadRequest, err))?;
+ let two= cx.param::<i64>("two").map_err(|err| tide::Error::new(StatusCode::BadRequest, err))?;
Ok((one + two).to_string())
}
