I've got some code like this (which doesn't work) (rocket and anyhow crates used, since this is my actual issue):
#[get("/")]
fn route() -> Result<&'static str, rocket::response::Debug<anyhow::Error>> {
various()?;
different()?;
errors()?;
can()?;
happen()?;
here()?;
Ok("response")
}
This would be no problem if the Error type in the Result is only anyhow::Error
rocket::response::Debug
however implements the From trait to convert arbitrary types that implement the Debug
trait.
My current idea to keep it simple is using a lambda like this:
#[get("/")]
fn route() -> Result<&'static str, rocket::response::Debug<anyhow::Error>> {
|| -> Result<_, anyhow::Error> {
various()?;
different()?;
errors()?;
can()?;
happen()?;
here()?;
}()?;
Ok("response")
}
But this has its own caveats and is not really ideal, is there a better solution that has a similar amount of boilerplate?