I have a Warp rejection handler, I'm using it like this,
.recover(handle_rejection)
It's declared like this,
pub async fn handle_rejection(err: Rejection) -> Result<impl warp::reply::Reply, Infallible> {
If both sides of the if
statement are the same type,
if let Some(e) = err.find::<crate::api::error::UserError>() {
Ok(warp::reply::with_status(
warp::reply::reply(),
warp::http::StatusCode::NOT_FOUND,
))
}
else {
Ok(warp::reply::with_status(
warp::reply::reply(),
warp::http::StatusCode::NOT_FOUND,
))
}
Everything works fine, but if change one of those sides to be,
Ok(e.into_response())
It's no longer ok, I get this error on compilation,
error[E0308]: mismatched types
--> src/api.rs:22:8
|
22 | Ok(warp::reply::with_status(
| ____________________^
23 | | warp::reply::reply(),
24 | | warp::http::StatusCode::NOT_FOUND,
25 | | ))
| |_________________^ expected struct `Response`, found struct `WithStatus`
|
I don't understand that though, because that side didn't change, this should still satisfy impl warp::reply::Reply
, what's the problem here?
I've tried different permutation of casting to the trait object explicitly like as warp::reply::Reply
and as &dyn warp::reply::Reply
but they don't work either.