-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Router::layer
should allow services whose Error: Into<Infallible>
#922
Comments
A potential worry here is if a layer supports multiple error types and is relying on the use-case to constrain it to a specific type, using Compare that with what we have now, where I have to wrap my layer in |
Sounds fine to me! |
* Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}` Fixes #922 * changelog
Turns out #924 was a breaking change so we have to yank+revert. So keeping this issue open for now. This has unfortunately has to wait until axum 0.6 which we don't have a timeline for at the moment. |
* Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}` Fixes #922 * changelog
#948 is open now which includes this, however as mentioned its a breaking change so we cannot merge it yet. However with the PR open I think I'll just close this for now as its accepted and implemented. |
* Prepare axum-next branch * Remove deprecated `extractor_middleware` function (#1077) * Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}` (#948) * Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}` (#924) * Allow `Error: Into<Infallible>` for `Route::{layer, route_layer}` Fixes #922 * changelog * fixup changelog * Panic on overlapping routes in `MethodRouter` (#1102) * Panic on overlapping routes in `MethodRouter` * changelog link * add test to ensure `head` and `get` don't overlap * Fix changelog * Prepare axum-next branch * Remove trailing slash redirects * changelog link * Fix changelog * remove asserting to make make the test more clear * remove tsr related feature * Add `RouterExt::route_with_tsr` * Apply suggestions from code review Co-authored-by: Jonas Platte <jplatte+git@posteo.de> * Update axum-extra/src/routing/mod.rs Co-authored-by: Jonas Platte <jplatte+git@posteo.de> * fix typos in docs * Update axum/CHANGELOG.md Co-authored-by: Jonas Platte <jplatte+git@posteo.de> * mention `RouterExt::route_with_tsr` in the changelog Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
Bug Report
Version
axum v0.4.8
axum v0.5.0
Crates
axum
Description
I'm writing a generic
tower::Service
that needs to wrap two other services and thus combine their errors. I would like to represent this using a strongly-typed error enum, to be able to distinguish between errors raised by either service. The problem is if both services haveError = Infallible
then my service will still have a strongly-typed uninhabited error. It can't ever produce an error but it won't be compatible withaxum::Router::layer()
.My idea here is to implement
From<MyError<Infallible, Infallible>> for Infallible
such that my error can be trivially converted toInfallible
if it's uninhabited. This still won't make it directly compatible withRouter::layer()
though, but ifRouter::layer()
requiredError: Into<Infallible>
rather thanError = Infallible
it would all work.More generally, any time that implements
Into<Infallible>
is presumably uninhabited, and axum really just cares that the error isn't possible rather than needing it to be the specific typeInfallible
. And so this should be reflected in the type system.The text was updated successfully, but these errors were encountered: