Proposal: Return Into<Response>
from endpoints
#596
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Contingent on #570. With that PR merged, we can convert any Result into a Response, which means that we can allow endpoints to return
Into<Response>
. This means that hello world examples becomeapp.at("/").get(|_| async { "hello world" })
again, but for endpoints with error handling logic that requires?
, they can returnResult<generic Into<Response>, generic Into<tide::Error>>
.The only breaking change people will run into with this is that for closure-style endpoints that previously inferred a return type, they will need to change
Ok(into_response)
intotide::Result::Ok(into_response)
or if?
is unused, just returninto_response
. This is because rust cannot infer what the error type is with just|_| async { Ok(…) }
.I personally believe that this tradeoff is worthwhile. My hunch is that most route handlers that are fallible also already have explicit Result signatures, and that the ability to skip Ok() in infallbile endpoints is a valuable reduction of boilerplate.
For
async fn
route handler definitions with an explicitResult<Response>
return signature, this doesn't break any code, but will optionally allow any infallible handler to return Response (or anything that'sInto<Response>
).To see how this would impact actual usage, check out the updated examples and tide code.
This will also play well with #580, as it will allow
All changes specific to this PR are in this commit: 7a68050